Resolve bundled modules with import semantics#4286
Open
samwgoldman wants to merge 1 commit into
Open
Conversation
Summary: Before this diff, the bundled stubs were created by simply inserting file paths in order directly into a module map. This means the modules depend on the order of files in the archive, but two different paths can sometimes provide the same module, and Python's own precedence rules do not match. In practice, there is only one example where this is a problem, which is exactly the issue in facebook#1819: `pandas/io/parsers.pyi` vs `pandas/io/parsers/__init__.pyi`. While the contents of the archives is fixed at compile time, we are not fully in control of the archives -- they come from typeshed or stubs repos written by someone else. This PR implements a new `Bundle` abstraction that takes an archive and uses Python runtime lookup rules to create the accurate module map. I added tests for other cases which don't currently exist in the current archives, but if they ever appear we will handle them correctly. This is an alternative approach to facebook#4185 Fixes facebook#1819 Differential Revision: D113606265
Contributor
|
@samwgoldman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113606265. |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Before this diff, the bundled stubs were created by simply inserting file paths in order directly into a module map. This means the modules depend on the order of files in the archive, but two different paths can sometimes provide the same module, and Python's own precedence rules do not match.
In practice, there is only one example where this is a problem, which is exactly the issue in #1819:
pandas/io/parsers.pyivspandas/io/parsers/__init__.pyi.While the contents of the archives is fixed at compile time, we are not fully in control of the archives -- they come from typeshed or stubs repos written by someone else. This PR implements a new
Bundleabstraction that takes an archive and uses Python runtime lookup rules to create the accurate module map.I added tests for other cases which don't currently exist in the current archives, but if they ever appear we will handle them correctly.
This is an alternative approach to #4185
Fixes #1819
Differential Revision: D113606265