horast
horast copied to clipboard
# type: ignore leads to AssertionError
If the following code:
class foo:
def bar(self): # whatever comment
pass
bar.__baz__ = None # type: ignore
is passed to horast.parse
, an AssertionError is raised:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/zdenal/.local/lib/python3.6/site-packages/horast/parser.py", line 19, in parse
tree = insert_comment_tokens(code, tree, comment_tokens)
File "/home/zdenal/.local/lib/python3.6/site-packages/horast/ast_comments.py", line 27, in insert_comment_tokens
path_to_anchor, before_anchor = find_in_ast(code, tree, nodes, scope)
File "/home/zdenal/.local/lib/python3.6/site-packages/horast/ast_tools.py", line 144, in find_in_ast
scopes = get_ast_node_scopes(code, nodes)
File "/home/zdenal/.local/lib/python3.6/site-packages/horast/ast_tools.py", line 72, in get_ast_node_scopes
assert len(ast_nodes) == len(nodes), (len(ast_nodes), len(nodes))
AssertionError: (12, 13)
If I replace # type: ignore
by normal comment, it works. Also, if # whatever comment
is removed, it works. Tested with horast version 0.3.1. Any ideas? Many thanks!