Commit 50fc847
authored
Omit errors for class pattern matches against object (#19709)
Since the class pattern matches any subclass, it can also be used to
check whether the matched object has a specific attribute. Mypy should
not emit an error for it.
```py
match m:
case object(foo=_):
m.foo
```
Using `object` for it is recommended in [PEP
635](https://peps.python.org/pep-0635/#history-and-context) and more
prominently in the precursor [PEP
622](https://peps.python.org/pep-0622/#class-patterns).1 parent 881a35a commit 50fc847
3 files changed
+22
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
275 | 279 | | |
276 | 280 | | |
277 | 281 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
671 | 671 | | |
672 | 672 | | |
673 | 673 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
680 | 683 | | |
681 | 684 | | |
682 | 685 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1003 | 1003 | | |
1004 | 1004 | | |
1005 | 1005 | | |
| 1006 | + | |
1006 | 1007 | | |
1007 | 1008 | | |
1008 | 1009 | | |
| 1010 | + | |
1009 | 1011 | | |
1010 | 1012 | | |
1011 | 1013 | | |
1012 | 1014 | | |
1013 | 1015 | | |
1014 | 1016 | | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
1015 | 1024 | | |
1016 | 1025 | | |
1017 | 1026 | | |
| |||
0 commit comments