Whole file

t3rn0/ast-comments

The author described this change as fix: handle multiple statements in one line. It counts as a record because the check below fails on the code as it stood at ac4dc0019 and passes on 8a50afae7, with nothing else changed between the two runs.

Fix saved2022-11-13
Sharing licenceMIT · LICENSE
Change size+4 3

What the code was meant to do, written into the code itself as a save note

fix: handle multiple statements in one line

The change

3636 comment_tokens = sorted(
3737 (x.start[0], x) for x in tokens if x.type == tokenize.COMMENT
3838 )
39- nodes = sorted([(x.lineno, x) for x in ast.walk(tree) if isinstance(x, ast.stmt)])
40-
39+ nodes = sorted(
40+ (x.lineno, x.col_offset, x) for x in ast.walk(tree) if isinstance(x, ast.stmt)
41+ )
4142 i = j = 0
4243 while i < len(comment_tokens) and j < len(nodes):
4344 t_lineno, token = comment_tokens[i]
44- n_lineno, node = nodes[j]
45+ n_lineno, _, node = nodes[j]
4546 if t_lineno <= n_lineno:
4647 node.comments += (format_comment(token.string),)
4748 i += 1

The check that tells the two apart

failpass·test_ast_commets.py::test_multiple_statements_in_line

Check file test_ast_commets.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 itac4dc0019ddadc1744ba456f473fb624e13eccdb
Broken version dated2022-08-03
Moduleast_comments
Units changed_enrich
Fingerprintcb86cec6d80b5937
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