mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
gh-102444: Fix minor bugs in test_typing
highlighted by pyflakes (GH-102445)
(cherry picked from commit 96e1022929
)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
db8d10beb3
commit
a7ec32e7d4
1 changed files with 2 additions and 19 deletions
|
@ -469,7 +469,6 @@ class TypeVarTests(BaseTestCase):
|
||||||
|
|
||||||
def test_bad_var_substitution(self):
|
def test_bad_var_substitution(self):
|
||||||
T = TypeVar('T')
|
T = TypeVar('T')
|
||||||
P = ParamSpec("P")
|
|
||||||
bad_args = (
|
bad_args = (
|
||||||
(), (int, str), Union,
|
(), (int, str), Union,
|
||||||
Generic, Generic[T], Protocol, Protocol[T],
|
Generic, Generic[T], Protocol, Protocol[T],
|
||||||
|
@ -1033,8 +1032,6 @@ class TypeVarTupleTests(BaseTestCase):
|
||||||
|
|
||||||
def test_repr_is_correct(self):
|
def test_repr_is_correct(self):
|
||||||
Ts = TypeVarTuple('Ts')
|
Ts = TypeVarTuple('Ts')
|
||||||
T = TypeVar('T')
|
|
||||||
T2 = TypeVar('T2')
|
|
||||||
|
|
||||||
class G1(Generic[*Ts]): pass
|
class G1(Generic[*Ts]): pass
|
||||||
class G2(Generic[Unpack[Ts]]): pass
|
class G2(Generic[Unpack[Ts]]): pass
|
||||||
|
@ -1304,7 +1301,7 @@ class TypeVarTupleTests(BaseTestCase):
|
||||||
i = Callable[[None], *Ts]
|
i = Callable[[None], *Ts]
|
||||||
j = Callable[[None], Unpack[Ts]]
|
j = Callable[[None], Unpack[Ts]]
|
||||||
self.assertEqual(i.__args__, (type(None), *Ts))
|
self.assertEqual(i.__args__, (type(None), *Ts))
|
||||||
self.assertEqual(i.__args__, (type(None), Unpack[Ts]))
|
self.assertEqual(j.__args__, (type(None), Unpack[Ts]))
|
||||||
|
|
||||||
k = Callable[[None], tuple[int, *Ts]]
|
k = Callable[[None], tuple[int, *Ts]]
|
||||||
l = Callable[[None], Tuple[int, Unpack[Ts]]]
|
l = Callable[[None], Tuple[int, Unpack[Ts]]]
|
||||||
|
@ -1432,8 +1429,6 @@ class TypeVarTupleTests(BaseTestCase):
|
||||||
self.assertEqual(g.__annotations__, {'args': (*Ts,)[0]})
|
self.assertEqual(g.__annotations__, {'args': (*Ts,)[0]})
|
||||||
|
|
||||||
def test_variadic_args_with_ellipsis_annotations_are_correct(self):
|
def test_variadic_args_with_ellipsis_annotations_are_correct(self):
|
||||||
Ts = TypeVarTuple('Ts')
|
|
||||||
|
|
||||||
def a(*args: *tuple[int, ...]): pass
|
def a(*args: *tuple[int, ...]): pass
|
||||||
self.assertEqual(a.__annotations__,
|
self.assertEqual(a.__annotations__,
|
||||||
{'args': (*tuple[int, ...],)[0]})
|
{'args': (*tuple[int, ...],)[0]})
|
||||||
|
@ -4769,7 +4764,6 @@ class OverloadTests(BaseTestCase):
|
||||||
# Definitions needed for features introduced in Python 3.6
|
# Definitions needed for features introduced in Python 3.6
|
||||||
|
|
||||||
from test import ann_module, ann_module2, ann_module3, ann_module5, ann_module6
|
from test import ann_module, ann_module2, ann_module3, ann_module5, ann_module6
|
||||||
import asyncio
|
|
||||||
|
|
||||||
T_a = TypeVar('T_a')
|
T_a = TypeVar('T_a')
|
||||||
|
|
||||||
|
@ -6898,16 +6892,6 @@ class AnnotatedTests(BaseTestCase):
|
||||||
self.assertEqual(get_type_hints(C, globals())['classvar'], ClassVar[int])
|
self.assertEqual(get_type_hints(C, globals())['classvar'], ClassVar[int])
|
||||||
self.assertEqual(get_type_hints(C, globals())['const'], Final[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]}
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_cannot_subclass(self):
|
def test_cannot_subclass(self):
|
||||||
with self.assertRaisesRegex(TypeError, "Cannot subclass .*Annotated"):
|
with self.assertRaisesRegex(TypeError, "Cannot subclass .*Annotated"):
|
||||||
class C(Annotated):
|
class C(Annotated):
|
||||||
|
@ -7335,7 +7319,6 @@ class ParamSpecTests(BaseTestCase):
|
||||||
self.assertEqual(B.__args__, ((int, str,), Tuple[bytes, float]))
|
self.assertEqual(B.__args__, ((int, str,), Tuple[bytes, float]))
|
||||||
|
|
||||||
def test_var_substitution(self):
|
def test_var_substitution(self):
|
||||||
T = TypeVar("T")
|
|
||||||
P = ParamSpec("P")
|
P = ParamSpec("P")
|
||||||
subst = P.__typing_subst__
|
subst = P.__typing_subst__
|
||||||
self.assertEqual(subst((int, str)), (int, str))
|
self.assertEqual(subst((int, str)), (int, str))
|
||||||
|
@ -7628,7 +7611,7 @@ class SpecialAttrsTests(BaseTestCase):
|
||||||
self.assertEqual(fr.__module__, 'typing')
|
self.assertEqual(fr.__module__, 'typing')
|
||||||
# Forward refs are currently unpicklable.
|
# Forward refs are currently unpicklable.
|
||||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
with self.assertRaises(TypeError) as exc:
|
with self.assertRaises(TypeError):
|
||||||
pickle.dumps(fr, proto)
|
pickle.dumps(fr, proto)
|
||||||
|
|
||||||
self.assertEqual(SpecialAttrsTests.TypeName.__name__, 'TypeName')
|
self.assertEqual(SpecialAttrsTests.TypeName.__name__, 'TypeName')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue