diff options
| -rw-r--r-- | Lib/test/test_typing.py | 8 | ||||
| -rw-r--r-- | Lib/typing.py | 10 | ||||
| -rw-r--r-- | Misc/NEWS.d/next/Library/2022-03-12-11-30-42.bpo-46981.ltWCxH.rst | 2 | 
3 files changed, 5 insertions, 15 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index e88f7322b2..bcffdc882d 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -469,14 +469,12 @@ class TypeVarTupleTests(BaseTestCase):          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]]) @@ -4248,7 +4246,7 @@ class GetUtilitiesTestCase(TestCase):          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), ()) diff --git a/Lib/typing.py b/Lib/typing.py index 6930f5ddac..e8613625c3 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1220,7 +1220,6 @@ class _GenericAlias(_BaseGenericAlias, _root=True):          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 @@ -1503,8 +1502,6 @@ class _CallableType(_SpecialGenericAlias, _root=True):  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 ...: @@ -1735,13 +1732,6 @@ class Generic:          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).""" diff --git a/Misc/NEWS.d/next/Library/2022-03-12-11-30-42.bpo-46981.ltWCxH.rst b/Misc/NEWS.d/next/Library/2022-03-12-11-30-42.bpo-46981.ltWCxH.rst new file mode 100644 index 0000000000..29f7c9376f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-03-12-11-30-42.bpo-46981.ltWCxH.rst @@ -0,0 +1,2 @@ +``typing.get_args(typing.Tuple[()])`` now returns ``()`` instead of +``((),)``.  | 
