t3rn0 / ast-comments

Extension to the built-in ast module. Finds comments in source code and adds them to the parsed tree.
MIT License
31 stars 10 forks source link

TypeError: '<' not supported between instances of 'Assign' and 'Assign' #2

Closed rrhg closed 2 years ago

rrhg commented 2 years ago

code = "a=1;b=1;print(a+b)"

no error ==> tree = ast.parse(code)

error from ==> tree = ast_comments.parse(code) File "/home/.../ast_comments.py", line 39, in _enrich nodes = sorted([(x.lineno, x) for x in ast.walk(tree) if isinstance(x, ast.stmt)]) TypeError: '<' not supported between instances of 'Assign' and 'Assign'

t3rn0 commented 2 years ago

Thank you for opening this issue. I've missed out that there can be multiple statements in one line. With the current version (0.1.2) it's possible to parse the code from your example

rrhg commented 2 years ago

Thanks!. That was fast. I'll try again.

t3rn0 commented 2 years ago

related to the subject https://github.com/t3rn0/ast-comments/issues/4#issue-1447534472