(tokens)
| 278 | raise NannyNag(e.lineno, e.msg, e.text) |
| 279 | |
| 280 | def _process_tokens(tokens): |
| 281 | INDENT = tokenize.INDENT |
| 282 | DEDENT = tokenize.DEDENT |
| 283 | NEWLINE = tokenize.NEWLINE |
| 284 | JUNK = tokenize.COMMENT, tokenize.NL |
| 285 | indents = [Whitespace("")] |
| 286 | check_equal = 0 |
| 287 | |
| 288 | for (type, token, start, end, line) in tokens: |
| 289 | if type == NEWLINE: |
| 290 | # a program statement, or ENDMARKER, will eventually follow, |
| 291 | # after some (possibly empty) run of tokens of the form |
| 292 | # (NL | COMMENT)* (INDENT | DEDENT+)? |
| 293 | # If an INDENT appears, setting check_equal is wrong, and will |
| 294 | # be undone when we see the INDENT. |
| 295 | check_equal = 1 |
| 296 | |
| 297 | elif type == INDENT: |
| 298 | check_equal = 0 |
| 299 | thisguy = Whitespace(token) |
| 300 | if not indents[-1].less(thisguy): |
| 301 | witness = indents[-1].not_less_witness(thisguy) |
| 302 | msg = "indent not greater e.g. " + format_witnesses(witness) |
| 303 | raise NannyNag(start[0], msg, line) |
| 304 | indents.append(thisguy) |
| 305 | |
| 306 | elif type == DEDENT: |
| 307 | # there's nothing we need to check here! what's important is |
| 308 | # that when the run of DEDENTs ends, the indentation of the |
| 309 | # program statement (or ENDMARKER) that triggered the run is |
| 310 | # equal to what's left at the top of the indents stack |
| 311 | |
| 312 | # Ouch! This assert triggers if the last line of the source |
| 313 | # is indented *and* lacks a newline -- then DEDENTs pop out |
| 314 | # of thin air. |
| 315 | # assert check_equal # else no earlier NEWLINE, or an earlier INDENT |
| 316 | check_equal = 1 |
| 317 | |
| 318 | del indents[-1] |
| 319 | |
| 320 | elif check_equal and type not in JUNK: |
| 321 | # this is the first "real token" following a NEWLINE, so it |
| 322 | # must be the first token of the next program statement, or an |
| 323 | # ENDMARKER; the "line" argument exposes the leading whitespace |
| 324 | # for this statement; in the case of ENDMARKER, line is an empty |
| 325 | # string, so will properly match the empty string with which the |
| 326 | # "indents" stack was seeded |
| 327 | check_equal = 0 |
| 328 | thisguy = Whitespace(line) |
| 329 | if not indents[-1].equal(thisguy): |
| 330 | witness = indents[-1].not_equal_witness(thisguy) |
| 331 | msg = "indent not equal e.g. " + format_witnesses(witness) |
| 332 | raise NannyNag(start[0], msg, line) |
| 333 | |
| 334 | |
| 335 | def __getattr__(name): |
no test coverage detected
searching dependent graphs…