Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions Lib/test/test_typing.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -473,7 +473,6 @@ def test_var_substitution(self):

def test_bad_var_substitution(self):
T = TypeVar('T')
P = ParamSpec("P")
Copy link
MemberAuthor

@AlexWaygoodAlexWaygoodMar 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P here is currently an unused variable. ParamSpec.__typing_subst__ is tested in another place in this file:

deftest_bad_var_substitution(self):
T=TypeVar('T')
P=ParamSpec('P')
bad_args= (42, int, None, T, int|str, Union[int, str])
forarginbad_args:
withself.subTest(arg=arg):
withself.assertRaises(TypeError):
P.__typing_subst__(arg)
withself.assertRaises(TypeError):
typing.Callable[P, T][arg, str]
withself.assertRaises(TypeError):
collections.abc.Callable[P, T][arg, str]

bad_args = (
(), (int, str), Union,
Generic, Generic[T], Protocol, Protocol[T],
Expand DownExpand Up@@ -1037,8 +1036,6 @@ class G2(Generic[Unpack[Ts]]): pass

def test_repr_is_correct(self):
Ts = TypeVarTuple('Ts')
T = TypeVar('T')
T2 = TypeVar('T2')

class G1(Generic[*Ts]): pass
class G2(Generic[Unpack[Ts]]): pass
Expand DownExpand Up@@ -1307,7 +1304,7 @@ def test_callable_args_are_correct(self):
i = Callable[[None], *Ts]
j = Callable[[None], Unpack[Ts]]
self.assertEqual(i.__args__, (type(None), *Ts))
self.assertEqual(i.__args__, (type(None), Unpack[Ts]))
self.assertEqual(j.__args__, (type(None), Unpack[Ts]))
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The j variable is currently unused. Given the pattern of the assertions immediately below, it seems pretty clear that it was meant to be used here.


k = Callable[[None], tuple[int, *Ts]]
l = Callable[[None], Tuple[int, Unpack[Ts]]]
Expand DownExpand Up@@ -1435,8 +1432,6 @@ def g(*args: *Ts): pass
self.assertEqual(g.__annotations__,{'args': (*Ts,)[0]})

def test_variadic_args_with_ellipsis_annotations_are_correct(self):
Ts = TypeVarTuple('Ts')

def a(*args: *tuple[int, ...]): pass
self.assertEqual(a.__annotations__,
{'args': (*tuple[int, ...],)[0]})
Expand DownExpand Up@@ -4918,7 +4913,6 @@ def test_overload_registry_repeated(self):
# Definitions needed for features introduced in Python 3.6

from test import ann_module, ann_module2, ann_module3, ann_module5, ann_module6
import asyncio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typing in Python is definitely synchronous ;)


T_a = TypeVar('T_a')

Expand DownExpand Up@@ -7077,16 +7071,6 @@ class C:
self.assertEqual(get_type_hints(C, globals())['classvar'], ClassVar[int])
self.assertEqual(get_type_hints(C, globals())['const'], Final[int])

def test_hash_eq(self):
self.assertEqual(len({Annotated[int, 4, 5], Annotated[int, 4, 5]}), 1)
self.assertNotEqual(Annotated[int, 4, 5], Annotated[int, 5, 4])
self.assertNotEqual(Annotated[int, 4, 5], Annotated[str, 4, 5])
self.assertNotEqual(Annotated[int, 4], Annotated[int, 4, 4])
self.assertEqual(
{Annotated[int, 4, 5], Annotated[int, 4, 5], Annotated[T, 4, 5]},
{Annotated[int, 4, 5], Annotated[T, 4, 5]}
)

Comment on lines -7080 to -7089
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is exactly identical to test_hash_eq on line 7015:

deftest_hash_eq(self):
self.assertEqual(len({Annotated[int, 4, 5], Annotated[int, 4, 5]}), 1)
self.assertNotEqual(Annotated[int, 4, 5], Annotated[int, 5, 4])
self.assertNotEqual(Annotated[int, 4, 5], Annotated[str, 4, 5])
self.assertNotEqual(Annotated[int, 4], Annotated[int, 4, 4])
self.assertEqual(
{Annotated[int, 4, 5], Annotated[int, 4, 5], Annotated[T, 4, 5]},
{Annotated[int, 4, 5], Annotated[T, 4, 5]}
)

def test_cannot_subclass(self):
with self.assertRaisesRegex(TypeError, "Cannot subclass .*Annotated"):
class C(Annotated):
Expand DownExpand Up@@ -7515,7 +7499,6 @@ class Y(Generic[P, T]):
self.assertEqual(B.__args__, ((int, str,), Tuple[bytes, float]))

def test_var_substitution(self):
T = TypeVar("T")
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T here is currently an unused variable. TypeVar.__typing_subst__ is tested more fully elsewhere:

deftest_var_substitution(self):
T=TypeVar('T')
subst=T.__typing_subst__
self.assertIs(subst(int), int)
self.assertEqual(subst(list[int]), list[int])
self.assertEqual(subst(List[int]), List[int])
self.assertEqual(subst(List), List)
self.assertIs(subst(Any), Any)
self.assertIs(subst(None), type(None))
self.assertIs(subst(T), T)
self.assertEqual(subst(int|str), int|str)
self.assertEqual(subst(Union[int, str]), Union[int, str])

P = ParamSpec("P")
subst = P.__typing_subst__
self.assertEqual(subst((int, str)), (int, str))
Expand DownExpand Up@@ -7835,7 +7818,7 @@ def test_special_attrs2(self):
self.assertEqual(fr.__module__, 'typing')
# Forward refs are currently unpicklable.
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.assertRaises(TypeError) as exc:
with self.assertRaises(TypeError):
pickle.dumps(fr, proto)

self.assertEqual(SpecialAttrsTests.TypeName.__name__, 'TypeName')
Expand Down