Skip to content

Conversation

@suleymanozkeskin
Copy link

@suleymanozkeskin suleymanozkeskin commented Dec 5, 2025

Improves type inference for union types with multiple generic parameters like
Ok[T] | Err[E] by adding union-pairing logic to the constraint solver.

Changes:

  • Added union element pairing with typevar confinement checks in generics.rs
  • Added 3 tests to type_guards.md

Summary

Following the explanatory comment, made by @carljm, I made some refactoring which I hope addresses the issue on the correct place.

I am not sure if this is still a right or suitable fix that matches the further plans of the maintainers on this topic.

Fixes astral-sh/ty#1703

Test Plan

I used the existing markdown test suite with additional test cases to cover the issue I opened + the case mentioned here

   Improves type inference for union types with multiple generic parameters like
   Ok[T] | Err[E] by adding union-pairing logic to the constraint solver.

   Changes:
     - Added union element pairing with typevar confinement checks in generics.rs
     - Added 3 tests to type_guards.md
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Dec 5, 2025
@AlexWaygood AlexWaygood changed the title Fixes https://github.com/astral-sh/ty/issues/1703 [ty] Improve typevar solving when encountering unions of generic types Dec 5, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 5, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 5, 2025

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/_logging.py:153:13: warning[unsupported-base] Unsupported class base with type `<class 'Mapping[str, Style]'> | <class 'Mapping[str, Divergent]'>`
- Found 42 diagnostics
+ Found 41 diagnostics

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/_typing.pyi:1217:16: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 5517 diagnostics
+ Found 5518 diagnostics

No memory usage changes detected ✅

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.

typevar solver can't solve a generic union

2 participants