Skip to content

Commit 12c4798

Browse files
committed
Add miscellaneous tests
1 parent e589a26 commit 12c4798

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/test_typing_extensions.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5499,6 +5499,25 @@ def foobar(x: List['X']): ...
54995499
get_type_hints(foobar, globals(), locals(), include_extras=True),
55005500
{'x': List[Annotated[int, (1, 10)]]}
55015501
)
5502+
def foobar2(x: list['X']): ...
5503+
if sys.version_info >= (3, 11):
5504+
self.assertEqual(
5505+
get_type_hints(foobar2, globals(), locals()),
5506+
{'x': list[int]}
5507+
)
5508+
self.assertEqual(
5509+
get_type_hints(foobar2, globals(), locals(), include_extras=True),
5510+
{'x': list[Annotated[int, (1, 10)]]}
5511+
)
5512+
else: # TODO: evaluate nested forward refs in Python < 3.11
5513+
self.assertEqual(
5514+
get_type_hints(foobar2, globals(), locals()),
5515+
{'x': list['X']}
5516+
)
5517+
self.assertEqual(
5518+
get_type_hints(foobar2, globals(), locals(), include_extras=True),
5519+
{'x': list['X']}
5520+
)
55025521
BA = Tuple[Annotated[T, (1, 0)], ...]
55035522
def barfoo(x: BA): ...
55045523
self.assertEqual(get_type_hints(barfoo, globals(), locals())['x'], Tuple[T, ...])
@@ -5973,6 +5992,15 @@ def run():
59735992
# The actual test:
59745993
self.assertEqual(result1, result2)
59755994

5995+
def test_subclass(self):
5996+
if sys.version_info >= (3, 10):
5997+
with self.assertRaises(TypeError):
5998+
class MyParamSpec(ParamSpec):
5999+
pass
6000+
else:
6001+
class MyParamSpec(ParamSpec): # Does not raise
6002+
pass
6003+
59766004

59776005
class ConcatenateTests(BaseTestCase):
59786006
def test_basics(self):
@@ -6382,6 +6410,14 @@ def test_pickle(self):
63826410
pickled = pickle.dumps(Self, protocol=proto)
63836411
self.assertIs(Self, pickle.loads(pickled))
63846412

6413+
@skipUnless(TYPING_3_10_0, "PEP 604 has yet to be")
6414+
def test_or(self):
6415+
self.assertEqual(Self | int, Union[Self, int])
6416+
self.assertEqual(int | Self, Union[int, Self])
6417+
6418+
self.assertEqual(get_args(Self | int), (Self, int))
6419+
self.assertEqual(get_args(int | Self), (int, Self))
6420+
63856421

63866422
class UnpackTests(BaseTestCase):
63876423
def test_basic_plain(self):

0 commit comments

Comments
 (0)