Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-46981: Remove typing._TypingEmpty #31836

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 3 additions & 5 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,12 @@ class G(Generic[Unpack[Ts]]): pass

for A in G, Tuple:
B = A[Unpack[Ts]]
if A != Tuple:
self.assertEqual(B[()], A[()])
self.assertEqual(B[()], A[()])
self.assertEqual(B[float], A[float])
self.assertEqual(B[float, str], A[float, str])

C = List[A[Unpack[Ts]]]
if A != Tuple:
self.assertEqual(C[()], List[A[()]])
self.assertEqual(C[()], List[A[()]])
self.assertEqual(C[float], List[A[float]])
self.assertEqual(C[float, str], List[A[float, str]])

Expand Down Expand Up @@ -4232,7 +4230,7 @@ class C(Generic[T]): pass
self.assertEqual(get_args(Union[int, Callable[[Tuple[T, ...]], str]]),
(int, Callable[[Tuple[T, ...]], str]))
self.assertEqual(get_args(Tuple[int, ...]), (int, ...))
self.assertEqual(get_args(Tuple[()]), ((),))
self.assertEqual(get_args(Tuple[()]), ())
self.assertEqual(get_args(Annotated[T, 'one', 2, ['three']]), (T, 'one', 2, ['three']))
self.assertEqual(get_args(List), ())
self.assertEqual(get_args(Tuple), ())
Expand Down
10 changes: 0 additions & 10 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,6 @@ def __init__(self, origin, args, *, inst=True, name=None,
if not isinstance(args, tuple):
args = (args,)
self.__args__ = tuple(... if a is _TypingEllipsis else
() if a is _TypingEmpty else
a for a in args)
self.__parameters__ = _collect_parameters(args)
self._paramspec_tvars = _paramspec_tvars
Expand Down Expand Up @@ -1502,8 +1501,6 @@ def __getitem_inner__(self, params):
class _TupleType(_SpecialGenericAlias, _root=True):
@_tp_cache
def __getitem__(self, params):
if params == ():
return self.copy_with((_TypingEmpty,))
if not isinstance(params, tuple):
params = (params,)
if len(params) >= 2 and params[-1] is ...:
Expand Down Expand Up @@ -1734,13 +1731,6 @@ def __init_subclass__(cls, *args, **kwargs):
cls.__parameters__ = tuple(tvars)


class _TypingEmpty:
"""Internal placeholder for () or []. Used by TupleMeta and CallableMeta
to allow empty list/tuple in specific places, without allowing them
to sneak in where prohibited.
"""


class _TypingEllipsis:
"""Internal placeholder for ... (ellipsis)."""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``typing.get_args(typing.Tuple[()])`` returns now ``()`` instead of
``((),)``.