Skip to content

Commit 2340770

Browse files
added generic type check
1 parent a20d4c7 commit 2340770

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
@@ -3318,6 +3318,25 @@ def test_mapping_pattern_duplicate_key_edge_case3(self):
33183318

33193319
class TestTypeErrors(unittest.TestCase):
33203320

3321+
def test_generic_type(self):
3322+
t = list[str]
3323+
w = None
3324+
with self.assertRaises(TypeError):
3325+
match ["s"]:
3326+
case t():
3327+
w = 0
3328+
self.assertIsNone(w)
3329+
3330+
def test_legacy_generic_type(self):
3331+
from typing import List
3332+
t = List[str]
3333+
w = None
3334+
with self.assertRaises(TypeError):
3335+
match ["s"]:
3336+
case t():
3337+
w = 0
3338+
self.assertIsNone(w)
3339+
33213340
def test_accepts_positional_subpatterns_0(self):
33223341
class Class:
33233342
__match_args__ = ()
@@ -3450,6 +3469,16 @@ def test_patma_legacy_union_type(self):
34503469
w = 0
34513470
self.assertIsNone(w)
34523471

3472+
def test_generic_union_type(self):
3473+
from typing import List
3474+
t = list[str] | List[str]
3475+
w = None
3476+
with self.assertRaises(TypeError):
3477+
match ["s"]:
3478+
case t():
3479+
w = 0
3480+
self.assertIsNone(w)
3481+
34533482
def test_regular_protocol(self):
34543483
from typing import Protocol
34553484
class P(Protocol): ...

0 commit comments

Comments
 (0)