Whole file
t3rn0/ast-comments
The author described this change as “fix: comments order for multiline expr”. It counts as a record because the check below fails on the code as it stood at ab0c7df55 and passes on bc8242f2b, with nothing else changed between the two runs.
Projectt3rn0/ast-comments
Fix saved2023-02-11
Sharing licenceMIT · LICENSE
Change size+4 −1
What the code was meant to do, written into the code itself as a save note
fix: comments order for multiline expr
The change
| 2 | 2 | import sys | |
| 3 | 3 | import tokenize | |
| 4 | 4 | from ast import * # noqa: F401,F403 | |
| 5 | + | from collections.abc import Iterable | |
| 5 | 6 | from typing import Dict, List, Tuple, Union | |
| 6 | 7 | ||
| 7 | 8 | ||
| ⋯ | |||
| 71 | 72 | ||
| 72 | 73 | attr = getattr(target_node, target_attr) | |
| 73 | 74 | attr.append(c_node) | |
| 74 | - | attr.sort(key=lambda x: (x.lineno, not isinstance(x, Comment))) | |
| 75 | + | attr.sort(key=lambda x: (x.end_lineno, not isinstance(x, Comment))) | |
| 75 | 76 | ||
| 76 | 77 | ||
| 77 | 78 | def _get_tree_intervals( | |
| ⋯ | |||
| 82 | 83 | attr_intervals = [] | |
| 83 | 84 | for attr in _CONTAINER_ATTRS: | |
| 84 | 85 | if items := getattr(node, attr, None): | |
| 86 | + | if not isinstance(items, Iterable): | |
| 87 | + | continue | |
| 85 | 88 | attr_intervals.append((*_get_interval(items), attr)) | |
| 86 | 89 | if attr_intervals: | |
| 87 | 90 | low = node.lineno if hasattr(node, "lineno") else min(attr_intervals)[0] | |
The check that tells the two apart
fail→pass·test_parse.py::test_comment_to_multiline_expr
Check file test_parse.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itab0c7df5566aca786fad73233dbfc2612f876e77
Broken version dated2023-02-05
Moduleast_comments
Units changed_enrich, _get_tree_intervals
Fingerprintec1794e43668693e
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.