Skip to content

Commit 72bff0f

Browse files
added generic type check
1 parent 58c903b commit 72bff0f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Lib/test/test_patma.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,6 +3309,25 @@ def test_mapping_pattern_duplicate_key_edge_case3(self):
33093309

33103310
class TestTypeErrors(unittest.TestCase):
33113311

3312+
def test_generic_type(self):
3313+
t = list[str]
3314+
w = None
3315+
with self.assertRaises(TypeError):
3316+
match ["s"]:
3317+
case t():
3318+
w = 0
3319+
self.assertIsNone(w)
3320+
3321+
def test_legacy_generic_type(self):
3322+
from typing import List
3323+
t = List[str]
3324+
w = None
3325+
with self.assertRaises(TypeError):
3326+
match ["s"]:
3327+
case t():
3328+
w = 0
3329+
self.assertIsNone(w)
3330+
33123331
def test_accepts_positional_subpatterns_0(self):
33133332
class Class:
33143333
__match_args__ = ()
@@ -3441,6 +3460,16 @@ def test_patma_legacy_union_type(self):
34413460
w = 0
34423461
self.assertIsNone(w)
34433462

3463+
def test_generic_union_type(self):
3464+
from typing import List
3465+
t = list[str] | List[str]
3466+
w = None
3467+
with self.assertRaises(TypeError):
3468+
match ["s"]:
3469+
case t():
3470+
w = 0
3471+
self.assertIsNone(w)
3472+
34443473
def test_regular_protocol(self):
34453474
from typing import Protocol
34463475
class P(Protocol): ...

0 commit comments

Comments
 (0)