Skip to content
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

Fix crash in PEP 561 module resolution #6000

Merged
merged 1 commit into from
Dec 4, 2018

Conversation

emmatyping
Copy link
Collaborator

If there was a py.typed file in a stub-only package, and it didn't
contain partial, there would be an unbound local error. To fix this,
we treat it as a normal stub-only package if the py.typed file doesn't
contain partial.

Fixes #5999

@wcooley this should fix the crash.

If there was a py.typed file in a stub-only package, and it didn't
contain "partial", there would be an unbound local error. To fix this,
we treat it as a normal stub-only package instead.
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely need to cherry-pick this. "Be liberal in what you accept" etc. (https://en.wikipedia.org/wiki/Robustness_principle)

@gvanrossum
Copy link
Member

Does it make sense to print a warning in the edge case? (Not sure if that would make things worse, since except if you're the package author, there's not much you can do about that warning.)

@emmatyping
Copy link
Collaborator Author

Yeah I thought about that, but if

@emmatyping
Copy link
Collaborator Author

Bah phones. The above should read:
"Yeah I thought about that but if we silently treat it as a normal package it will just not resolve the Python package, which we will report. Therefore the natural debugging check is to check if you included partial. Though maybe we should mention partial packages in the module not found message? "

@gvanrossum
Copy link
Member

Oh, it would be easy to add that to https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports (where that message no redirects). So go ahead and merge now!

@emmatyping emmatyping merged commit 3a89c8a into python:master Dec 4, 2018
@emmatyping emmatyping deleted the fixpep561crash branch December 4, 2018 11:25
JukkaL pushed a commit that referenced this pull request Dec 4, 2018
If there was a py.typed file in a stub-only package, and it didn't
contain "partial", there would be an unbound local error. To fix this,
we treat it as a normal stub-only package instead.
@JukkaL JukkaL mentioned this pull request Dec 4, 2018
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.

Unbound local due to missing "partial\n" in py.typed
2 participants