Invalid pattern in pattern matching
Reports incorrect or ambiguous use of structural pattern matching in Python class patterns and __match_args__ definitions.
This inspection helps you catch issues such as:
Using positional patterns for a class that does not define
__match_args__.Providing more positional patterns than the class exposes via
__match_args__.Specifying the same attribute both positionally and by keyword in a single class pattern.
Defining
__match_args__with invalid type (must betuple[str, ...]).
For certain simple as-patterns with built-in classes, it also suggests a quick fix to simplify the pattern.
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
PyPattern- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
The inspection provides quick fixes where possible, for example to add __match_args__, remove redundant patterns, or simplify certain as-patterns involving built-in classes.
Inspection ID: PyPatternInspection
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: | CLion 2026.1, DataSpell 2026.1, IntelliJ IDEA 2026.1, PyCharm 2026.1, Qodana for JVM 2026.1, |