-
Notifications
You must be signed in to change notification settings - Fork 166
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
PR: move special case from walk to _ScopeVisitor._ImportFrom #538
Conversation
I'm not quite sure why this special case of overwriting the ast was added there, but from the comment, this seems to imply that it's for Python 2. If that is the reason, then we should just remove the Python 2 version of the code entirely, we no longer support Python 2. We can remove the comment as well if it's no longer relevant. |
@lieryan Hmm. A unit test will fail if the special case is completely removed. It's still a big mystery. I agree that the comments re the test aren't very useful. |
IIUC, this is because the special case is normalising the ast so that the it looks more like how Python 2 parses things rather than how Python 3 does things. That's why removing it causes a test to fail, because the current code is expecting the ast to behave like Python 2, namely that .module is an empty string rather than None. The ideal fix is to remove that special case, and instead fix the code so it expects .module to be set to None instead for these cases. |
Assuming there's no other use of node.module, then changing this line:
To this:
Should fix it. Alternatively, |
Previously, we were patching the AST here to set ImportFrom.module to empty string as a workaround for normalizing AST differences with Python 2. We no longer support Python 2, so this is no longer necessary.
Hi @edreamleo, thanks for looking into this. I believe this PR and the additional commit 3eba333 should solve the issue, but do let me know if you think there's more that meets the eye. |
@lieryan Many thanks, Lie, for this work. It looks better than the code I was imagining. In particular:
Both these changes help remove the distinction between |
@lieryan I'm having trouble syncing my master master (in my fork) with the upstream master. Everything appears up-to-date. I followed these instructions. Are you sure your master contains the new code? |
@lieryan In my master branch (not yet containing this PR), there are three instances of the string
I wonder what would happen (after merging this PR) if this code became:
|
The I guess if you really want to avoid adding an empty string token there, you can change the code to append the token:
Looking at the code further though, I think this code has another bug to begin with. You can add spaces between the dots, this is valid Python code:
But because |
@lieryan Thanks for these comments. I've noted them and will investigate further as soon as I begin studying Rope's inference machinery. It will be several days at least before that happens. |
An experimental fix for #537. This PR should not be merged without further discussion, study and testing.
I speculate that the special case may have been added to the walk function for "generality/safety", but clearly the special case logically belongs elsewhere.