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

Tweak the typing spec's module resolution to more closely emulate Python's runtime semantics #1772

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jun 8, 2024

This PR implements the changes to the typing spec's module resolution order that have been proposed on Discourse. Three changes have been made:

  1. Typeshed’s standard-library stubs have been moved higher in the resolution order, above any items that originate from site-packages.
  2. With the change from point (1), it becomes more important that type checkers provide a clear and easy way for users to override the vendored copy of typeshed’s standard-library stubs with a custom directory of standard-library stubs if they want to. Most major type checkers already implement this (mypy provides the --custom-typeshed-dir option; pyright provides the typeshedPath configuration-file option; pyre provides the --typeshed option). This update to the spec formally specifies that doing so is highly encouraged.
  3. The PR brings back an explicit mention in the typing spec of where vendored typeshed stubs for third-party packages (if there are any that the type checker has chosen to vendor) should come in the module resolution order (last!). This was specified in PEP 561, but the relevant language was removed from the typing spec in [spec] Update typeshed language to conform to reality #1571.

Please see the Discourse topic for a detailed rationale for these changes, and please post any substantive feedback on the proposed changes there rather than on this PR. (Suggestions for minor wording improvements are welcome here.)

As discussed on Discourse, the proposed new specification appears to already be implemented by mypy, but pyright's behaviour would have to change to become conformant with the new spec. (I have not surveyed pyre's and pytype's module resolution behaviour.)

@AlexWaygood AlexWaygood added the Typing Council decision Needs to be approved by the Typing Council. Do not merge until approved. label Jun 8, 2024
Copy link
Contributor

@emmatyping emmatyping left a comment

Choose a reason for hiding this comment

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

As the original PEP author I like this change. It better reflects the current ecosystem of type checkers.

@carljm
Copy link
Member

carljm commented Jun 17, 2024

Typing council members have all signed off on this. @AlexWaygood, ready for merge?

@AlexWaygood
Copy link
Member Author

I was waiting for at least a week after filing the Typing Council issue, as per the process described at https://github.com/python/typing-council?tab=readme-ov-file#decisions. But as of this morning, it is exactly 7 days since I posted that issue, so perhaps I'm good to go now!

@JelleZijlstra JelleZijlstra merged commit 9642a5a into python:main Jun 18, 2024
5 checks passed
@AlexWaygood AlexWaygood deleted the module-resolution branch June 18, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing Council decision Needs to be approved by the Typing Council. Do not merge until approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants