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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ''.

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.

i = ImportAll(n.module, n.level) # type: ImportBase
else:
i = ImportFrom(self.translate_module_id(n.module) if n.module is not None else '',
Expand Down