[ty] Use Top materializations for TypeIs special form by AlexWaygood · Pull Request #20591 · astral-sh/ruff (original) (raw)

@AlexWaygood added the ty

Multi-file analysis & type inference

label

Sep 26, 2025

@AlexWaygood

@AlexWaygood

@AlexWaygood AlexWaygood changed the titleUse Top materializations for TypeIs special form [ty] Use Top materializations for TypeIs special form

Sep 26, 2025

carljm

AlexWaygood

@AlexWaygood

dcreager added a commit that referenced this pull request

Sep 30, 2025

@dcreager

suleymanozkeskin added a commit to suleymanozkeskin/ruff-ty-typeis-fix that referenced this pull request

Dec 1, 2025

@suleymanozkeskin

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:

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 }})