Repository navigation
[ty] Default-specialize class objects in meta-protocol checks - #28265
Merged
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 97.84%. The percentage of expected errors that received a diagnostic held steady at 96.28%. The number of fully passing files held steady at 128/145. |
Memory usage reportMemory usage unchanged ✅ |
|
carljm
added a commit
that referenced
this pull request
Sep 14, 2026
…aliases * origin/main: (21 commits) [ty] Share attribute write compatibility checks (#28555) [ty] Prefer `ty.toml` and `pyproject.toml` over playground `ty.json` (#28449) [`ruff`, `flake8-use-pathlib`] Support `parent_mode` (`RUF064`, `PTH103`) (#28528) [`pyupgrade`] Make the fix for `UP040` always unsafe (#28526) [`pyupgrade`] Skip `TypeVarTuple` and `ParamSpec` conversions with bounds or constraints (`UP040`, `UP046`, `UP047`) (#28505) [ty] Escape glob characters in anchored directory paths (#28518) [ty] Handle gradual metaclass ancestry and conflicts (#28474) [ty] Preserve recursive metadata in union transformations (#28497) [ty] Refactor "desperate" import resolution to use candidate operations that will also apply to module enumeration. (#28543) [ty] Report override conflicts introduced by new bases (#28530) [ty] Resolve dependencies within correlated inference alternatives (#28252) [ty] Extract shared abstract-method analysis (#28537) [ty] Reject reassignment of enum members (#28462) [ty] Preserve runtime comparison semantics when narrowing tagged unions (#28053) [ty] Extract a method on `NameResolver` to advance resolution by single module name component. (#28540) [ty] Return root discovery to `NameResolver`, but retain necessary interface changes (#28536) [ty] Default-specialize class objects in meta-protocol checks (#28265) [ty] Extract module root discovery from `NameResolver`. (#28531) [ty] Fix MRO ordering for generic bases (#28172) [ty] Run benchmarks for auto-imports in CI (#28490) ... # Conflicts: # crates/ty_python_semantic/src/types/narrow.rs
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.
Bare generic class objects were checked against
type[P]using constructor return types that retained the class's type variables, even though ordinary class-member lookup already applies the default specialization. This could reject compatible classes and leak class-scoped type variables into generic protocol inference. In pyochain, those variables also trigger an expensive recursive protocol proof when passing bareOktoand_then; this PR improves our overall type-check time for pyochain by ~8x.Apply the default specialization when obtaining the constructed type for meta-protocol checking and inference, including inference from unions of class objects. A shared helper keeps those paths consistent. Explicit specializations, custom
__new__and metaclass__call__return types, and all structural member checks are preserved. Ordinary constructor and callable inference are unchanged.One of many PRs fixing problems uncovered by astral-sh/ty#4269.
Test plan
Added mdtests cover declared and missing type-parameter defaults, incompatible default specializations, explicit arguments, unions of bare classes, preservation of caller type variables, unbound methods,
functools.partial, custom__new__returns, and metaclass__call__returns.Local checks on all 115 tracked Python files in the unchanged pyochain checkout retain the same 514 diagnostics. A callable-inference control still infers
Result[str, str]when passed bareOk.