Repository navigation
[ty] Preserve stdlib identity when search paths overlap - #29064
Open
charliermarsh wants to merge 1 commit into
Open
charliermarsh wants to merge 1 commit into
charliermarsh wants to merge 1 commit into
Conversation
charliermarsh
force-pushed
the
charlie/fix-ty-523
branch
from
October 2, 2026 00:17
9fba6d2 to
89bd174
Compare
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 98.24%. The percentage of expected errors that received a diagnostic held steady at 98.24%. The number of fully passing files held steady at 134/146. |
Memory usage reportMemory usage unchanged ✅ |
|
| Project | Old Time | New Time | Change |
|---|---|---|---|
git-revise |
0.12s | 0.05s | -57% |
charliermarsh
marked this pull request as ready for review
October 2, 2026 01:43
charliermarsh
force-pushed
the
charlie/fix-ty-523
branch
from
October 5, 2026 14:43
89bd174 to
5b8f63c
Compare
charliermarsh
requested review from
AlexWaygood
and removed request for
dhruvmanila
October 7, 2026 01:40
charliermarsh
force-pushed
the
charlie/fix-ty-523
branch
from
October 7, 2026 02:00
5b8f63c to
f59dcb6
Compare
This branch was successfully deployed
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
We now preserve the identity of standard-library stubs when a custom typeshed overlaps a first-party or extra search path. This fixes the module-identification error behind the dependency-cycle panic in astral-sh/ty#523.
The two configuration settings establish different import roots:
typeshedselects the standard-library stubs to use instead of our bundled stubs. Withtypeshed = "./typings", we look under./typings/stdlib/.extra-pathsadds high-priority import roots for Python modules and stubs. Withextra-paths = ["./typings"], we search./typings/directly.For example, a custom stub distribution can contain both additional modules and standard-library replacements:
Here,
rootidentifies our first-party import roots. Animport devicefindstypings/device.pyithrough the extra path, whileimport pathlibfindstypings/stdlib/pathlib.pyithrough typeshed. This overlapping layout, as used by the MicroPython stubs in #2819, remains supported.The ambiguity arises when we identify a file we are already analyzing. Depending on the search root, the same
typings/stdlib/typing.pyifile can have three names:typings/stdlib/typingtypings/stdlib.typingtypings.stdlib.typingPreviously, an earlier extra or first-party path could determine that identity, even when we originally found the file through a standard-library import. We then failed to recognize its builtin or typing definitions as having special behavior. In the reported case, inference followed paths that formed an unhandled dependency cycle and panicked. Losing that special handling can also produce incorrect types even when inference does not panic.
We now derive the identity of standard-library stub files from the configured stdlib root first:
builtins.pyiisbuiltins, andtyping.pyiistyping. This preserves the semantics needed to check ordinary Python code with the configuration above:We resolve the canonical name using normal precedence and Python-version availability, and verify that it selects the same file. If it is shadowed or unavailable, we do not fall back to an alias under an enclosing search path.
We also change how we handle an exact duplicate of the stdlib import root:
We now search
./typings/stdlibonly at the stdlib position, after the other extra paths and project roots. In this example,overrides/pathlib.pyiwins. The same applies when the stdlib directory appears inroot.Listing the stdlib directory in
extra-pathsorrootno longer lets users:.pyfiles from it through that entry.VERSIONSfile excludes for the configured Python version.The configuration is still accepted, but code relying on those behaviors can break. The earlier
extra-paths = ["./typings"]layout still supports additional stubs such asdevice.pyi. Runtime lookup is unchanged.Closes astral-sh/ty#523.