-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix regression with empty package names #4115
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
Conversation
@@ -651,7 +651,7 @@ def visit_Import(self, n: ast3.Import) -> Import: | |||
def visit_ImportFrom(self, n: ast3.ImportFrom) -> ImportBase: | |||
assert n.level is not None | |||
if len(n.names) == 1 and n.names[0].name == '*': | |||
assert n.module is not None | |||
assert n.module is not '' |
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.
Are you sure is not ''
is the right thing to do? I'd expect n.module != ''
.
@@ -651,7 +651,7 @@ def visit_Import(self, n: ast3.Import) -> Import: | |||
def visit_ImportFrom(self, n: ast3.ImportFrom) -> ImportBase: | |||
assert n.level is not None | |||
if len(n.names) == 1 and n.names[0].name == '*': | |||
assert n.module is not None | |||
assert n.module is not '' |
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.
This is actually not what I meant. The fix should at least replace n.module = None
with n.module = ''
.
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.
if n.module is None:
n.module = ''
Is this what you mean?
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.
Yes, but it may be more subtle than that. --strict-optional
handling requires care, so I need to investigate this myself in any case.
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.
OK, it looks like you can write
mod = n.module if n.module is not None else ''
i = ImportAll(mod, n.level)
Also please make the corresponding change in fastparse2.py
and add tests (check that the import does not crash in both Python 2 and Python mode).
(I think this is something we should get into the next release, so it is better not to wait with this.)
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.
@matzipan Is there any progress on this? It is a crash so I don't want the fix to wait indefinitely.
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.
My new pipeline is failing on this, fix would be really appreciated.
Can you work around it by removing the toplevel __init__.py?
|
This needs a test, so other bugs won't cause similar regressions in the future without being caught. |
Fixes #4111