[ty] Add a new diagnostic to detect invalid class patterns in match statements by abhijeetbodas2001 · Pull Request #22939 · astral-sh/ruff (original) (raw)
added the ty
Multi-file analysis & type inference
label
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
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
AlexWaygood added a commit that referenced this pull request
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
carljm added a commit that referenced this pull request
- main: (43 commits)
[
ruff] Suppress diagnostic for strings with backslashes in interpolations before Python 3.12 (RUF027) (#21069) [flake8-bugbear] Fix B023 false positive for immediately-invoked lambdas (#23294) [ty] AddFinalmdtests for loops and redeclaration (#23331) [flake8-pyi] Also check string annotations (PYI041) (#19023) Remove AlexWaygood as a flake8-pyi codeowner (#23347) [ty] Add comments to clarify the purpose ofNominalInstanceType::class_nameandNominalInstanceType::class_module_name(#23339) Add attestations for release artifacts and Docker images (#23111) [ty] Fixassert_typediagnostic messages (#23342) [ty] Force-update all insta snapshots (#23343) Add Q004 to the list of conflicting rules (#23340) [ty] Fixinvalid-match-patternfalse positives (#23338) [ty] new diagnostic called-match-pattern-must-be-a-type (#22939) [ty] Update flaky projects (#23337) [ty] Increase timeout for ecosystem report to 40 min (#23336) Bump ecosystem-analyzer pin (#23335) [ty] Replacestrsimwith CPython-based Levenshtein implementation (#23291) [ty] Add mdtest for staticmethod assigned in class body (#23330) [ty] fix inferring type variable from string literal argument (#23326) [ty] bytes literal is a sequence of integers (#23329) Update rand and getrandom (#23333) ...
KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request
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 }})