[ty] Add a new diagnostic to detect invalid class patterns in match statements by abhijeetbodas2001 · Pull Request #22939 · astral-sh/ruff (original) (raw)

@AlexWaygood added the ty

Multi-file analysis & type inference

label

Jan 29, 2026

abhijeetbodas2001

@abhijeetbodas2001 abhijeetbodas2001 changed the title[ty] [DRAFT] new diagnostic called-match-pattern-must-be-a-type [ty] new diagnostic called-match-pattern-must-be-a-type

Feb 8, 2026

sharkdp

@abhijeetbodas2001

@abhijeetbodas2001

@sharkdp

@AlexWaygood AlexWaygood changed the title[ty] new diagnostic called-match-pattern-must-be-a-type [ty] Add a new diagnostic to detect invalid class patterns in match statements

Feb 16, 2026

AlexWaygood added a commit that referenced this pull request

Feb 16, 2026

@AlexWaygood

Summary

Any type type can only be inhabited by class objects; any type | <dynamic type> union could materialize to a class object; and any <class object> & <dynamic type> intersection is a subtype of a class object. So using a value that inhabits any of these types as a class pattern should not cause us to emit the invalid-match-pattern diagnostic.

This PR fixes several false positives that showed up in the ecosystem report in #22939

Test Plan

mdtests added

AlexWaygood

carljm added a commit that referenced this pull request

Feb 16, 2026

@carljm

KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request

May 1, 2026

@AlexWaygood

Summary

Any type type can only be inhabited by class objects; any type | <dynamic type> union could materialize to a class object; and any <class object> & <dynamic type> intersection is a subtype of a class object. So using a value that inhabits any of these types as a class pattern should not cause us to emit the invalid-match-pattern diagnostic.

This PR fixes several false positives that showed up in the ecosystem report in astral-sh/ruff#22939

Test Plan

mdtests added

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