Skip to content

Fix crash in PEP 561 module resolution - #6000

Merged
emmatyping merged 1 commit into
python:masterfrom
emmatyping:fixpep561crash
Dec 4, 2018
Merged

emmatyping merged 1 commit into
python:masterfrom
emmatyping:fixpep561crash

Conversation

@emmatyping

Copy link
Copy Markdown
Member

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.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member Author

Yeah I thought about that, but if

@emmatyping

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