Skip to content

Resolve generated stubs alongside editable packages - #4535

Open
ting-hong-shieh wants to merge 1 commit into
meta:mainfrom
ting-hong-shieh:fix/2859-generated-stubs
Open

ting-hong-shieh wants to merge 1 commit into
meta:mainfrom
ting-hong-shieh:fix/2859-generated-stubs

Conversation

@ting-hong-shieh

Copy link
Copy Markdown
Contributor

Summary

  • preserve typed namespace roots when a later search root contains an editable regular package
  • use those typed roots as overlays when resolving package submodules
  • retain the regular package's __init__.py as the package module
  • add resolver-level and end-to-end regressions for generated extension stubs

Root cause

Generated stubs installed next to an extension module form an implicit namespace package. When an editable source directory later supplied the package's __init__.py, normal regular-package precedence discarded the earlier namespace root, so submodules such as _core.pyi were no longer visible.

The overlay is limited to namespace roots containing py.typed, preserving existing behavior for ordinary implicit namespace packages.

User impact

Editable installs can expose their source package and generated extension stubs at the same time, so imported native APIs retain their declared types.

Testing

  • cargo test module::finder::tests (71 tests)
  • cargo test test_editable_install_generated_stub_overlay
  • formatter and Clippy through test.py

Fixes #2859

@meta-cla meta-cla Bot added the cla signed label Aug 13, 2026
@ting-hong-shieh
ting-hong-shieh marked this pull request as ready for review August 13, 2026 08:40
@meta-codesync

meta-codesync Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D115850824. (Because this pull request was imported automatically, there will not be any future comments.)

@ting-hong-shieh

Copy link
Copy Markdown
Contributor Author

The Meta Linter check is currently reporting Action Required, but the internal details are not accessible to external contributors. Could someone with access share the failing diagnostic so I can address it? Thanks!

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the stale label Aug 28, 2026
@ting-hong-shieh
ting-hong-shieh force-pushed the fix/2859-generated-stubs branch from 3000f2c to 8173d2e Compare September 4, 2026 05:03
@github-actions github-actions Bot added size/l and removed size/l labels Sep 4, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the stale label Sep 5, 2026
Keep generated stubs from typed namespace roots available when a later editable source directory provides the regular package initializer.
@github-actions github-actions Bot added size/l and removed size/l labels Sep 10, 2026
@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. ✅

@rchen152

rchen152 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@connernilsen would you be able to take a look at this one? At a glance, the code looks reasonable to me, but I think you have more context on what the intended/correct behavior should be.

@rchen152
rchen152 requested review from connernilsen and removed request for NathanTempest and maggiemoss November 3, 2026 00:15

This branch has not been deployed

No deployments
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.

Generated typestubs are not found in an editable install

5 participants