Skip to content

[ty] Pass unmapped type variables to SpecializationBuilder::build_with#24809

Merged
ibraheemdev merged 1 commit intomainfrom
ibraheem/spec-builder-choose
Apr 26, 2026
Merged

[ty] Pass unmapped type variables to SpecializationBuilder::build_with#24809
ibraheemdev merged 1 commit intomainfrom
ibraheem/spec-builder-choose

Conversation

@ibraheemdev
Copy link
Copy Markdown
Member

This is a small refactor, and means that we no longer have to manually compute the constraint set solutions just to change the default specialization of a given mapping.

@ibraheemdev ibraheemdev added the ty Multi-file analysis & type inference label Apr 23, 2026
BoundTypeVarInstance<'db>,
Option<(Type<'db>, Type<'db>)>,
) -> Option<Type<'db>>,
) -> Specialization<'db> {
Copy link
Copy Markdown
Member Author

@ibraheemdev ibraheemdev Apr 23, 2026

Choose a reason for hiding this comment

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

@dcreager I believe this should be forwards compatible with the planned changes to SpecializationBuilder because this hook runs after the creation of the constraint set, and hopefully just means more places can use SpecializationBuilder?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Talked about this in person, and I think I agree that it is forwards compatiable

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 23, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 87.94%. The percentage of expected errors that received a diagnostic held steady at 83.36%. The number of fully passing files held steady at 79/133.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 23, 2026

Memory usage report

Summary

Project Old New Diff Outcome
sphinx 259.63MB 259.64MB +0.00% (13.09kB)
trio 116.89MB 116.90MB +0.01% (10.42kB)
flake8 47.89MB 47.89MB +0.00% (524.00B)
prefect 709.29MB 709.29MB -0.00% (2.50kB) ⬇️

Significant changes

Click to expand detailed breakdown

sphinx

Name Old New Diff Outcome
GenericAlias<'db>::variance_of_ 16.12kB 22.86kB +41.79% (6.74kB)
GenericAlias<'db>::variance_of_::interned_arguments 13.43kB 18.84kB +40.31% (5.41kB)
Type<'db>::apply_specialization_::interned_arguments 1.44MB 1.43MB -0.29% (4.22kB)
Specialization 1004.14kB 1000.39kB -0.37% (3.75kB)
Type<'db>::apply_specialization_ 1.63MB 1.63MB -0.21% (3.54kB)
StaticClassLiteral<'db>::variance_of_ 22.96kB 25.53kB +11.18% (2.57kB)
StaticClassLiteral<'db>::variance_of_::interned_arguments 19.12kB 21.45kB +12.13% (2.32kB)
infer_scope_types_impl 15.46MB 15.47MB +0.01% (2.07kB)
is_redundant_with_impl 930.76kB 928.78kB -0.21% (1.98kB)
infer_definition_types 23.64MB 23.64MB +0.01% (1.70kB)
is_redundant_with_impl::interned_arguments 1.08MB 1.07MB -0.14% (1.55kB)
Type<'db>::class_member_with_policy_ 7.62MB 7.62MB +0.02% (1.52kB)
Type<'db>::try_call_dunder_get_ 4.86MB 4.87MB +0.03% (1.45kB)
Type<'db>::member_lookup_with_policy_ 6.84MB 6.84MB +0.02% (1.34kB)
Type<'db>::class_member_with_policy_::interned_arguments 4.02MB 4.03MB +0.03% (1.22kB)
... 21 more

trio

Name Old New Diff Outcome
Type<'db>::class_member_with_policy_ 2.03MB 2.04MB +0.07% (1.52kB)
StaticClassLiteral<'db>::try_mro_ 790.26kB 791.76kB +0.19% (1.50kB)
Type<'db>::try_call_dunder_get_ 1.34MB 1.34MB +0.11% (1.45kB)
Type<'db>::member_lookup_with_policy_ 1.94MB 1.94MB +0.07% (1.37kB)
Type<'db>::class_member_with_policy_::interned_arguments 1.12MB 1.12MB +0.11% (1.22kB)
Type<'db>::apply_specialization_::interned_arguments 624.53kB 623.67kB -0.14% (880.00B)
GenericAlias<'db>::variance_of_ 6.41kB 7.09kB +10.60% (696.00B)
StaticClassLiteral<'db>::variance_of_ 17.32kB 17.97kB +3.79% (672.00B)
StaticClassLiteral<'db>::variance_of_::interned_arguments 14.34kB 14.98kB +4.41% (648.00B)
GenericAlias<'db>::variance_of_::interned_arguments 5.41kB 6.05kB +11.69% (648.00B)
Type<'db>::apply_specialization_ 704.68kB 704.11kB -0.08% (580.00B)
StaticClassLiteral<'db>::try_mro_::interned_arguments 185.34kB 185.84kB +0.27% (504.00B)
Specialization 455.88kB 455.39kB -0.11% (496.00B)
code_generator_of_static_class 307.79kB 308.25kB +0.15% (472.00B)
infer_expression_type_impl 1.31MB 1.31MB -0.03% (396.00B)
... 28 more

flake8

Name Old New Diff Outcome
is_redundant_with_impl 83.48kB 82.38kB -1.32% (1.10kB)
StaticClassLiteral<'db>::try_mro_ 305.97kB 306.84kB +0.28% (884.00B)
GenericAlias<'db>::variance_of_ 2.50kB 3.34kB +33.80% (864.00B)
is_redundant_with_impl::interned_arguments 86.11kB 85.42kB -0.80% (704.00B)
StaticClassLiteral<'db>::variance_of_ 5.05kB 5.61kB +11.15% (576.00B)
GenericAlias<'db>::variance_of_::interned_arguments 1.97kB 2.53kB +28.57% (576.00B)
IntersectionType 45.23kB 44.68kB -1.23% (568.00B)
StaticClassLiteral<'db>::variance_of_::interned_arguments 4.43kB 4.92kB +11.11% (504.00B)
StaticClassLiteral<'db>::try_mro_::interned_arguments 69.82kB 70.10kB +0.40% (288.00B)
infer_statement_types_impl 6.06kB 5.81kB -4.06% (252.00B)
UnionType 52.38kB 52.16kB -0.42% (224.00B)
infer_definition_types 1.86MB 1.86MB -0.01% (216.00B)
infer_expression_types_impl 1.03MB 1.03MB -0.01% (120.00B)
infer_scope_types_impl 986.41kB 986.32kB -0.01% (84.00B)
InferableTypeVars<'db>::merge_::interned_arguments 2.53kB 2.60kB +2.78% (72.00B)
... 1 more

prefect

Name Old New Diff Outcome
Type<'db>::apply_specialization_::interned_arguments 2.97MB 2.96MB -0.34% (10.31kB) ⬇️
Specialization 2.12MB 2.11MB -0.44% (9.62kB) ⬇️
Type<'db>::apply_specialization_ 3.70MB 3.69MB -0.25% (9.52kB) ⬇️
GenericAlias<'db>::variance_of_ 579.80kB 588.82kB +1.56% (9.02kB) ⬇️
GenericAlias<'db>::variance_of_::interned_arguments 35.09kB 42.05kB +19.84% (6.96kB) ⬇️
is_redundant_with_impl 2.01MB 2.00MB -0.33% (6.77kB) ⬇️
is_redundant_with_impl::interned_arguments 2.13MB 2.12MB -0.27% (5.93kB) ⬇️
infer_expression_types_impl 63.30MB 63.30MB +0.01% (4.16kB) ⬇️
StaticClassLiteral<'db>::try_mro_ 4.25MB 4.26MB +0.09% (3.84kB) ⬇️
IntersectionType 709.05kB 705.30kB -0.53% (3.75kB) ⬇️
infer_definition_types 91.19MB 91.20MB +0.00% (3.70kB) ⬇️
Type<'db>::class_member_with_policy_ 17.70MB 17.70MB +0.02% (3.22kB) ⬇️
StaticClassLiteral<'db>::variance_of_ 205.44kB 208.49kB +1.48% (3.05kB) ⬇️
CallableType 2.15MB 2.15MB -0.14% (3.02kB) ⬇️
Type<'db>::try_call_dunder_get_ 10.61MB 10.62MB +0.03% (2.91kB) ⬇️
... 42 more

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 23, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-assignment 1 0 1
invalid-return-type 0 0 1
no-matching-overload 1 0 0
unresolved-attribute 0 1 0
unsupported-operator 0 1 0
Total 2 2 2

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Raw diff:

core (https://github.com/home-assistant/core)
- homeassistant/components/tado/climate.py:812:20 error[unsupported-operator] Operator `in` is not supported between objects of type `str | None` and `str | list[Unknown]`

meson (https://github.com/mesonbuild/meson)
- mesonbuild/backend/ninjabackend.py:1949:81 error[unresolved-attribute] Attribute `startswith` is not defined on `None` in union `str | None`
- mesonbuild/backend/ninjabackend.py:1950:34 error[invalid-assignment] Object of type `str` is not assignable to `Literal["2015", "2018", "2021"]`
+ mesonbuild/backend/ninjabackend.py:1950:34 error[invalid-assignment] Object of type `str | UnspecializedTypeVar` is not assignable to `Literal["2015", "2018", "2021"]`

pwndbg (https://github.com/pwndbg/pwndbg)
+ pwndbg/emu/emulator.py:551:36 error[invalid-assignment] Object of type `tuple[_T@filter, ...]` is not assignable to `tuple[str]`
+ pwndbg/emu/emulator.py:551:42 error[no-matching-overload] No overload of constructor `filter.__new__` matches arguments

werkzeug (https://github.com/pallets/werkzeug)
- src/werkzeug/datastructures/structures.py:532:16 error[invalid-return-type] Return type does not match returned value: expected `list[V@MultiDict]`, found `V@MultiDict | list[V@MultiDict]`
+ src/werkzeug/datastructures/structures.py:532:16 error[invalid-return-type] Return type does not match returned value: expected `list[V@MultiDict]`, found `V@MultiDict | list[Unknown]`

Full report with detailed diff (timing results)

BoundTypeVarInstance<'db>,
Option<(Type<'db>, Type<'db>)>,
) -> Option<Type<'db>>,
) -> Specialization<'db> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Talked about this in person, and I think I agree that it is forwards compatiable

@carljm carljm removed their request for review April 23, 2026 23:10
@ibraheemdev ibraheemdev merged commit 3de40f7 into main Apr 26, 2026
56 checks passed
@ibraheemdev ibraheemdev deleted the ibraheem/spec-builder-choose branch April 26, 2026 20:11
carljm added a commit to tamird/ruff that referenced this pull request Apr 27, 2026
* main: (248 commits)
  [ty] bump conformance suite commit (astral-sh#24848)
  [ty] Pass unmapped type variables to `SpecializationBuilder::build_with` (astral-sh#24809)
  [ty] Avoid bookkeeping for unannotated functions (astral-sh#24842)
  [ty] Optimize signature checking based on number of arguments (astral-sh#24674)
  [ty] Avoid eagerly inferring legacy generic context (astral-sh#24841)
  [ty] Skip decorator inference for undecorated functions (astral-sh#24839)
  [ty] solve unions against generic protocols (astral-sh#24837)
  [ty] Lazily allocate parameter type builders (astral-sh#24838)
  [ty] Lazily compute call argument fallbacks (astral-sh#24836)
  [ty] Avoid collecting type context callables (astral-sh#24835)
  Bump ecosystem-analyzer to e7576e6 (astral-sh#24834)
  [ty] Support basic narrowing with aliased conditional expressions (astral-sh#24302)
  [ty] Fix project and workspace selection (astral-sh#24824)
  [ty] Fix missing memory usage attributes (astral-sh#24823)
  Fix setting selection for multi folder workspace (astral-sh#24819)
  Improve diagnostics for implicit calls to a possibly unbound unary operator. (astral-sh#24816)
  [ty] Update review pool (astral-sh#24818)
  Bump 0.15.12 (astral-sh#24815)
  [ty] Complete support for more detailed diagnostics on possibly unbound errors from implicit dunder calls against unions. (astral-sh#24676)
  Implement `#ruff:file-ignore` file-level suppressions (astral-sh#23599)
  ...
carljm added a commit that referenced this pull request Apr 27, 2026
* main: (44 commits)
  Update cargo-bins/cargo-binstall action to v1.18.1 (#24855)
  Update dependency ruff to v0.15.12 (#24857)
  Update taiki-e/install-action action to v2.75.18 (#24864)
  [ty] Model bool-op branch snapshots (#24458)
  [ty] Support `Unpack[TypedDict]` in `**kwargs` signatures (#24653)
  Update prek dependencies (#24858)
  Update Rust crate bitflags to v2.11.1 (#24859)
  Update Rust crate clap to v4.6.1 (#24860)
  Update Rust crate mimalloc to v0.1.49 (#24862)
  Update Rust crate uuid to v1.23.1 (#24863)
  Update Rust crate rayon to v1.12.0 (#24866)
  Update Rust crate libc to v0.2.185 (#24861)
  [ty] Reserve union element storage (#24849)
  [ty] bump conformance suite commit (#24848)
  [ty] Pass unmapped type variables to `SpecializationBuilder::build_with` (#24809)
  [ty] Avoid bookkeeping for unannotated functions (#24842)
  [ty] Optimize signature checking based on number of arguments (#24674)
  [ty] Avoid eagerly inferring legacy generic context (#24841)
  [ty] Skip decorator inference for undecorated functions (#24839)
  [ty] solve unions against generic protocols (#24837)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants