| 10 | |
| 11 | |
| 12 | def checker(ast, in_loop, errors): |
| 13 | if ast is None: |
| 14 | return |
| 15 | in_loop = ( |
| 16 | in_loop |
| 17 | or ast.kind.startswith("for") |
| 18 | or ast.kind.startswith("while") |
| 19 | or ast.kind.startswith("async_for") |
| 20 | ) |
| 21 | if ast.kind in ("aug_assign1", "aug_assign2") and ast[0][0] == "and": |
| 22 | text = str(ast) |
| 23 | error_text = ( |
| 24 | "\n# improper augmented assignment (e.g. +=, *=, ...):\n#\t" |
| 25 | + "\n# ".join(text.split("\n")) |
| 26 | + "\n" |
| 27 | ) |
| 28 | errors.append(error_text) |
| 29 | |
| 30 | for node in ast: |
| 31 | if not in_loop and node.kind in ("continue", "break"): |
| 32 | text = str(node) |
| 33 | error_text = "\n# not in loop:\n#\t" + "\n# ".join(text.split("\n")) |
| 34 | errors.append(error_text) |
| 35 | if hasattr(node, "__repr1__"): |
| 36 | checker(node, in_loop, errors) |