Skip to content

[ty] Simplify TypeVar assignability/subtyping logic#24138

Merged
AlexWaygood merged 1 commit intomainfrom
claude/simplify-typevar-handling-L1gC7
Mar 23, 2026
Merged

[ty] Simplify TypeVar assignability/subtyping logic#24138
AlexWaygood merged 1 commit intomainfrom
claude/simplify-typevar-handling-L1gC7

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

Summary

Refactor the TypeVar type relation checking logic to simplify the control flow and eliminate redundant conditions. The change consolidates two separate match arms that handled inferable TypeVars into a single arm with conditional logic based on whether the relation is an assignability check.

Test Plan

Existing tests

Consolidate two separate match branches for `(_, Type::TypeVar)` when the
typevar is inferable into a single branch. The old code duplicated the
upper-bound check between the match guard and the body, with fallthrough
to a catch-all returning `self.never()`. Since `when_none_or` naturally
returns `always` for no bound and the check result otherwise (with `never`
matching the fallthrough behavior), the two branches can be merged.

https://claude.ai/code/session_016rAtEXYhnAGFW3ok4xARvQ
@AlexWaygood AlexWaygood added internal An internal refactor or improvement ty Multi-file analysis & type inference labels Mar 23, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 23, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 85.38%. The percentage of expected errors that received a diagnostic held steady at 78.70%. The number of fully passing files held steady at 64/132.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 23, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 23, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 0 40 0
invalid-return-type 0 1 0
Total 0 41 0

Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.

Full report with detailed diff (timing results)

@AlexWaygood AlexWaygood changed the title [ty] Simplify TypeVar assignability check logic [ty] Simplify TypeVar assignability/subtyping logic Mar 23, 2026
@AlexWaygood AlexWaygood marked this pull request as ready for review March 23, 2026 13:54
Copy link
Copy Markdown
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you!

@AlexWaygood AlexWaygood merged commit 146340c into main Mar 23, 2026
49 checks passed
@AlexWaygood AlexWaygood deleted the claude/simplify-typevar-handling-L1gC7 branch March 23, 2026 20:20
carljm added a commit that referenced this pull request Mar 25, 2026
* main: (36 commits)
  [ty] Reduce diagnostic range for `invalid-metaclass` (#24145)
  [ty] Simplify TypeVar assignability/subtyping logic (#24138)
  [ty] Prevent tainted loop bindings in cycle normalization (#24143)
  [ty] Add precisely-typed overloads for `TypedDict` update (#24101)
  [ty] Fix folding ranges of comments separated by statements (#24132)
  Bump ecosystem-analyzer pin (#24136)
  Bump ecosystem-analyzer pin (#24135)
  Simplify `NewType` handling in `relation.rs` (#24109)
  [ty] Add more tests for `NewType` subtyping (#24115)
  [ty] Add `NewType`s to the property tests (#24113)
  [ty] Prepare test files for unreachable code change (#24133)
  `analyze graph`: resolve string imports that reference attributes, not just modules (#24058)
  Update Artifact GitHub Actions dependencies (#24116)
  Update taiki-e/install-action action to v2.68.33 (#24130)
  Update taiki-e/install-action action to v2.68.32 (#24123)
  Update Rust crate serde_with to v3.18.0 (#24126)
  Update Swatinem/rust-cache action to v2.9.1 (#24127)
  Update Rust crate quick-junit to 0.6.0 (#24125)
  Update Rust crate clap to v4.6.0 (#24124)
  Update Rust crate tracing-subscriber to v0.3.23 (#24122)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants