Skip to content

Resolve bundled modules with import semantics#4286

Open
samwgoldman wants to merge 1 commit into
facebook:mainfrom
samwgoldman:export-D113606265
Open

Resolve bundled modules with import semantics#4286
samwgoldman wants to merge 1 commit into
facebook:mainfrom
samwgoldman:export-D113606265

Conversation

@samwgoldman

Copy link
Copy Markdown
Member

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.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 #4185

Fixes #1819

Differential Revision: D113606265

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
@meta-cla meta-cla Bot added the cla signed label Jul 24, 2026
@meta-codesync

meta-codesync Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@samwgoldman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113606265.

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pd.read_csv inferred type is Unknown but go to definition works.

2 participants