Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

matzipan
Copy link

@matzipan matzipan commented Oct 13, 2017

Fixes #4111

@@ -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 ''
Copy link
Contributor

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 ''
Copy link
Member

@ilevkivskyi ilevkivskyi Oct 13, 2017

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 = ''.

Copy link
Author

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?

Copy link
Member

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.

Copy link
Member

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.)

Copy link
Member

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.

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.

@gvanrossum
Copy link
Member

gvanrossum commented Nov 7, 2017 via email

@gvanrossum gvanrossum changed the title Fix regression with empty package names #4111 Fix regression with empty package names Nov 8, 2017
@gvanrossum
Copy link
Member

This needs a test, so other bugs won't cause similar regressions in the future without being caught.

@ilevkivskyi
Copy link
Member

Superseded by #4259
@matzipan Thank you for help!

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

Successfully merging this pull request may close these issues.

5 participants