Skip to content

# type: ignore leads to AssertionError #3

Description

@ZdenekM

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions