Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# type: ignore leads to AssertionError #3

Open
ZdenekM opened this issue Aug 5, 2019 · 7 comments
Open

# type: ignore leads to AssertionError #3

ZdenekM opened this issue Aug 5, 2019 · 7 comments

Comments

@ZdenekM
Copy link

ZdenekM commented Aug 5, 2019

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!

mbdevpl added a commit that referenced this issue Aug 7, 2019
@mbdevpl
Copy link
Owner

mbdevpl commented Aug 7, 2019

Indeed, I can confirm the error. For the time being I've created a branch which reproduces the error - I think the error might boil down to a too-strict assertion, i.e. maybe the code would just work with the assertion disabled. Have you tried running your code with -O (i.e. optimization flag passed to python that disables assertions)? Does it work then, or brakes somewhere else?

@ZdenekM
Copy link
Author

ZdenekM commented Aug 19, 2019

The issue seems to be gone with -O flag.

@ZdenekM
Copy link
Author

ZdenekM commented Oct 25, 2019

Any chance that this will be fixed soon? :) Thanks...

@mbdevpl
Copy link
Owner

mbdevpl commented Oct 29, 2019

Yeah, I'm working on this issue (and some related ones that emerged) right now. Feel free to test with current issue_3 branch - should be fixed there, but I'll do some more tests before merging and publishing new version.

@ZdenekM
Copy link
Author

ZdenekM commented Jan 22, 2020

I can confirm that the issue is fixed in issue_3 branch. Any chance that it will be merged and released to PyPI soon?

@mbdevpl
Copy link
Owner

mbdevpl commented Jan 29, 2020

Yes, sorry for the wait! And thanks for the verification. I'll get down to finalize those fixes soon!

@ZdenekM
Copy link
Author

ZdenekM commented Sep 16, 2020

@mbdevpl It would be great if you can make a new release containing this fix. The project I'm working on depends on horast and this issue causes some troubles :-) Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants