Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Commit007d6de
authored
Fixes#20358.As discovered by@randolf-scholz in#20142, `mypy` treats value patternsin match statement in a completely wrong way.From [PEP 622](https://peps.python.org/pep-0622/#literal-patterns):> Literal pattern uses equality with literal on the right hand side, sothat in the above example number == 0 and then possibly number == 1, etcwill be evaluated.Existing tests for the feature are invalid: for example,```pythonfoo: objectmatch foo: case 1: reveal_type(foo)```must reveal `object`, and test `testMatchValuePatternNarrows` assertsthe opposite. Here's a runtime example:```>>> class A:... def __eq__(self,o): return True... >>> match A():... case 1:... print("eq")... eq```I have updated the existing tests accordingly.The idea is that value patterns are essentially equivalent to `if foo ==SomeValue` checks, not `isinstance` checks modelled by`conditional_types_wit_intersection`.The original implementation was introduced in#10191.
1 parentf0b0fe7 commit007d6de
File tree
4 files changed
+91
-27
lines changed- mypy
- test-data/unit
4 files changed
+91
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6654 | 6654 | | |
6655 | 6655 | | |
6656 | 6656 | | |
| 6657 | + | |
| 6658 | + | |
| 6659 | + | |
| 6660 | + | |
| 6661 | + | |
| 6662 | + | |
| 6663 | + | |
| 6664 | + | |
| 6665 | + | |
| 6666 | + | |
| 6667 | + | |
| 6668 | + | |
| 6669 | + | |
| 6670 | + | |
| 6671 | + | |
| 6672 | + | |
| 6673 | + | |
| 6674 | + | |
| 6675 | + | |
| 6676 | + | |
| 6677 | + | |
| 6678 | + | |
6657 | 6679 | | |
6658 | 6680 | | |
6659 | 6681 | | |
| |||
6699 | 6721 | | |
6700 | 6722 | | |
6701 | 6723 | | |
6702 | | - | |
| 6724 | + | |
6703 | 6725 | | |
6704 | 6726 | | |
6705 | 6727 | | |
6706 | 6728 | | |
6707 | 6729 | | |
6708 | 6730 | | |
6709 | | - | |
| 6731 | + | |
6710 | 6732 | | |
6711 | | - | |
6712 | | - | |
6713 | | - | |
6714 | | - | |
6715 | | - | |
6716 | 6733 | | |
6717 | 6734 | | |
6718 | 6735 | | |
| |||
6947 | 6964 | | |
6948 | 6965 | | |
6949 | 6966 | | |
| 6967 | + | |
| 6968 | + | |
| 6969 | + | |
| 6970 | + | |
| 6971 | + | |
6950 | 6972 | | |
6951 | 6973 | | |
6952 | 6974 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
248 | 259 | | |
249 | 260 | | |
250 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
| |||
206 | 205 | | |
207 | 206 | | |
208 | 207 | | |
209 | | - | |
210 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
211 | 213 | | |
212 | | - | |
213 | | - | |
214 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
215 | 217 | | |
216 | 218 | | |
217 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
1742 | 1742 | | |
1743 | 1743 | | |
1744 | 1744 | | |
1745 | | - | |
| 1745 | + | |
1746 | 1746 | | |
1747 | 1747 | | |
1748 | 1748 | | |
1749 | 1749 | | |
1750 | | - | |
| 1750 | + | |
1751 | 1751 | | |
1752 | | - | |
| 1752 | + | |
| 1753 | + | |
1753 | 1754 | | |
1754 | 1755 | | |
1755 | 1756 | | |
| |||
1785 | 1786 | | |
1786 | 1787 | | |
1787 | 1788 | | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
1788 | 1817 | | |
1789 | 1818 | | |
1790 | 1819 | | |
| |||
2813 | 2842 | | |
2814 | 2843 | | |
2815 | 2844 | | |
2816 | | - | |
| 2845 | + | |
2817 | 2846 | | |
2818 | 2847 | | |
2819 | 2848 | | |
| |||
2822 | 2851 | | |
2823 | 2852 | | |
2824 | 2853 | | |
2825 | | - | |
| 2854 | + | |
2826 | 2855 | | |
2827 | 2856 | | |
2828 | 2857 | | |
| |||
2909 | 2938 | | |
2910 | 2939 | | |
2911 | 2940 | | |
2912 | | - | |
| 2941 | + | |
2913 | 2942 | | |
2914 | | - | |
| 2943 | + | |
2915 | 2944 | | |
2916 | 2945 | | |
2917 | 2946 | | |
| |||
0 commit comments
Comments
(0)