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
Fixes for 3.9 #56
Fixes for 3.9 #56
Conversation
Looks like there's a problem between github and travis, but here's the successful build: https://travis-ci.org/github/gristlabs/asttokens/builds/673368162 |
Hey Alex, any idea why I am getting this test failure when running locally?
Same happens if I make a virtual environment with Python 3.9-dev myself and run pytest from there. Using |
Sorry, no idea. |
Does it pass for you locally? Would you mind sharing instructions on how to install the relevant version of Python 3.9? The version I got from https://www.python.org/downloads/release/python-390a5/ doesn't seem to have the keyword changes that need this fix. (It has the Slice changes.) |
I used
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I can confirm that it works, but have one suggestion to distinguish the cases based on the node content rather than python version + node type.
asttokens/mark_tokens.py
Outdated
first_token = name | ||
# ast.keyword changed in 3.9 https://bugs.python.org/issue40141 | ||
# Astroid was not affected | ||
if sys.version_info < (3, 9) or not isinstance(node, ast.AST): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I looked a bit closer, and would like to propose this condition instead, which seems more meaningful. I checked that it works:
+ # Until python 3.9, ast keyword nodes didn't have line info. Astroid has lineno of None.
+ if node.arg is not None and getattr(node, 'lineno', None) is None:
(if it holds, apply old logic, else it's no longer needed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I'm surprised the attribute was actually missing before.
Closes #55, although it may be good to investigate further exactly what's going on with keywords and try to find a solution that doesn't involve checking for versions or astroid.
Git is being exhausting as usual, I don't know why it's included all these old commits.