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.

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

22 import sys
33 import tokenize
44 from ast import * # noqa: F401,F403
5+from collections.abc import Iterable
56 from typing import Dict, List, Tuple, Union
67
78
7172
7273 attr = getattr(target_node, target_attr)
7374 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)))
7576
7677
7778 def _get_tree_intervals(
8283 attr_intervals = []
8384 for attr in _CONTAINER_ATTRS:
8485 if items := getattr(node, attr, None):
86+ if not isinstance(items, Iterable):
87+ continue
8588 attr_intervals.append((*_get_interval(items), attr))
8689 if attr_intervals:
8790 low = node.lineno if hasattr(node, "lineno") else min(attr_intervals)[0]

The check that tells the two apart

failpass·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.

Other bugs found in t3rn0/ast-comments