[ty] Use Top materializations for TypeIs special form by AlexWaygood · Pull Request #20591 · astral-sh/ruff (original) (raw)
added the ty
Multi-file analysis & type inference
label
AlexWaygood changed the title
Use [ty] Use Top materializations for TypeIs special formTop materializations for TypeIs special form
dcreager added a commit that referenced this pull request
- main: (21 commits)
[ty] Literal promotion refactor (#20646)
[ty] Add tests for nested generic functions (#20631)
[
cli] Add conflict between--add-noqaand--diffoptions (#20642) [ty] Ensure first-party search paths always appear in a sensible order (#20629) [ty] Usetyping.Selffor the first parameter of instance methods (#20517) [ty] Remove unnecessaryparsed_module()calls (#20630) RemoveTextEmitter(#20595) [ty] Use fully qualified names to distinguish ambiguous protocols in diagnostics (#20627) [ty] Ecosystem analyzer: relax timeout thresholds (#20626) [ty] Apply type mappings to functions eagerly (#20596) [ty] Improve disambiguation of class names in diagnostics (#20603) Add the The Basics title back to CONTRIBUTING.md (#20624) [playground] Fix quick fixes for empty ranges in playground (#20599) Update dependency ruff to v0.13.2 (#20622) [ruff] Fix minor typos in doc comments (#20623) Update dependency PyYAML to v6.0.3 (#20621) Update cargo-bins/cargo-binstall action to v1.15.6 (#20620) Fixed documentation for try_consider_else (#20587) [ty] UseTopmaterializations forTypeIsspecial form (#20591) [ty] SimplifyAny | (Any & T)toAny(#20593) ...
suleymanozkeskin added a commit to suleymanozkeskin/ruff-ty-typeis-fix that referenced this pull request
Fixes astral-sh#1703
Fixes incomplete type narrowing when using TypeIs with generic union types like: Result[T, E] = Ok[T] | Err[E].
Previously, type parameter E was materialized to 'object' before specialization could substitute it with concrete types like Exception, causing narrowing to produce Err[Unknown] instead of Err[Exception].
Changes:
- Added is_materialized flag to TypeIsType to defer materialization
- Implemented class-based union element matching for multi-typevar unions in generics.rs
- Modified TypeIs creation to delay materialization until after specialization
- Added test case for generic TypeIs narrowing to type_guards.md
- Removed the comments which had a discussion about: astral-sh#20591
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
[ Show hidden characters]({{ revealButtonHref }})