Skip to content

Commit

Permalink
Removed code addressing python#468
Browse files Browse the repository at this point in the history
  • Loading branch information
Daraan committed Sep 25, 2024
1 parent efa1214 commit 66eebb1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
34 changes: 0 additions & 34 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7515,40 +7515,6 @@ def test_invalid_cases_before_3_11(self):
with self.assertRaises(TypeError):
ListOrSetT[(Generic[T], )]

def test_subscription_without_type_params(self):
Simple = TypeAliasType("Simple", int)
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
Simple[int]
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
Simple[[]]
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
Simple[()]

# A TypeVar in the value does not allow subscription
T = TypeVar('T')
MissingTypeParamsErr = TypeAliasType("MissingTypeParamsErr", List[T])
self.assertEqual(MissingTypeParamsErr.__type_params__, ())
self.assertEqual(MissingTypeParamsErr.__parameters__, ())
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
MissingTypeParamsErr[int]
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
MissingTypeParamsErr[[]]
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
MissingTypeParamsErr[()]

# However, providing type_params=() argument allows subscription
MissingTypeParams = TypeAliasType("MissingTypeParams", List[T], type_params=())
self.assertEqual(MissingTypeParams.__type_params__, ())
self.assertEqual(MissingTypeParams.__parameters__, ())
# These do not raise
MissingTypeParams[int]
MissingTypeParams[[]]
MissingTypeParams[()]
# These do not raise
Simple2 = TypeAliasType("Simple2", int, type_params=())
Simple2[int]
Simple2[[]]
Simple2[()]

def test_pickle(self):
global Alias
Expand Down
15 changes: 0 additions & 15 deletions src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3526,19 +3526,6 @@ def _raise_attribute_error(self, name: str) -> Never:
def __repr__(self) -> str:
return self.__name__

def _is_subscriptable(self):
if len(self.__parameters__) > 0:
return True
if _should_collect_from_parameters(self.__value__):
if hasattr(typing, '_collect_type_vars'):
more_parameters = _collect_type_vars((self.__value__,),
(TypeVar, ParamSpec))
else:
more_parameters = _collect_parameters((self.__value__,))
if more_parameters:
return True
return False

if sys.version_info < (3, 11):
def _check_single_param(self, param, recursion=0):
# Allow [], [int], [int, str], [int, ...], [int, T]
Expand Down Expand Up @@ -3572,8 +3559,6 @@ def _check_parameters(self, parameters):
]

def __getitem__(self, parameters):
if len(self.__parameters__) == 0 and not self._is_subscriptable():
raise TypeError("Only generic type aliases are subscriptable")
if not isinstance(parameters, tuple):
parameters = (parameters,)
parameters = self._check_parameters(parameters)
Expand Down

0 comments on commit 66eebb1

Please sign in to comment.