Skip to content

Comments

[ty] Prefer exact matches when solving constrained type variables#21165

Merged
ibraheemdev merged 1 commit intomainfrom
ibraheem/constrained-typevar-solving
Oct 31, 2025
Merged

[ty] Prefer exact matches when solving constrained type variables#21165
ibraheemdev merged 1 commit intomainfrom
ibraheem/constrained-typevar-solving

Conversation

@ibraheemdev
Copy link
Member

Summary

The solver is currently order-dependent, and will choose a supertype over the exact type if it appears earlier in the list of constraints. We could be smarter and try to choose the most precise subtype, but I imagine this is something the new constraint solver will fix anyways, and this fixes the issue showing up on #21070.

@ibraheemdev ibraheemdev added the ty Multi-file analysis & type inference label Oct 31, 2025
@github-actions
Copy link
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@github-actions
Copy link
Contributor

mypy_primer results

Changes were detected when running on open source projects
meson (https://github.com/mesonbuild/meson)
- mesonbuild/cargo/builder.py:63:36: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Token[bool]`, found `Token[int]`
- Found 1655 diagnostics
+ Found 1654 diagnostics
No memory usage changes detected ✅

Copy link
Member

@dcreager dcreager left a comment

Choose a reason for hiding this comment

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

Looks good! And this will be a nice regression test for when we start to land the new solver

@ibraheemdev ibraheemdev merged commit 1d6ae85 into main Oct 31, 2025
42 checks passed
@ibraheemdev ibraheemdev deleted the ibraheem/constrained-typevar-solving branch October 31, 2025 14:58
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