You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've written some tests to test nesting of Unpack with TypeAliasTypes, which causes TypeError: Substitution of bare TypeVarTuple is not supported during the recursive substitution.
This is currently only relevant for 3.11 as for lower versions Issue #103 needs to be addressed first.
@skipUnless(TYPING_3_11_0, "Needs Issue #103 first")deftest_nested_unpack(self):
T=TypeVar('T')
Ts=TypeVarTuple("Ts")
Variadic=TypeAliasType("Variadic", Tuple[int, Unpack[Ts]], type_params=(Ts,))
Variadic[int, Tuple[str, int]] # this is okTupleAliasTs=Variadic[Tuple[Unpack[Ts], int]]
# -------------------------------------------------# Tuple[int, Tuple[str, int]]# all below tests also fail so abort here early.TupleAliasTs[str] # <--- TypeError: Substitution of bare TypeVarTuple is not supported# -------------------------------------------------TupleAliasTsT=Variadic[Tuple[Unpack[Ts], T]]
withself.subTest("Single parameter for tuple alias"):
# Tuple[int, Tuple[str, object]]nested_tuple_A=TupleAliasTsT[str, object]
nested_tuple_A_unpack=TupleAliasTsT[Unpack[Tuple[str]], object]
self.assertEqual(nested_tuple_A, nested_tuple_A_unpack)
withself.subTest("Test invalid args", args=([str, int], object)):
# TypeError on some versions as types should be passedinvalid_nested_tuple=TupleAliasTsT[[str, int], object] # invalid formwithself.subTest("With Callable Ts"):
# Tuple[int, (str, int) -> object]CallableAliasTsT=Variadic[Callable[[Unpack[Ts]], T]]
CallableAliasTsT[[str, int], object] # valid nested tuple# Equivalent Formswithself.subTest("Equivalence of variadic arguments"):
nested_tuple_bare=TupleAliasTsT[str, int, object]
nested_tuple_B_1xUnpack=TupleAliasTsT[Unpack[Tuple[str, int]], object]
nested_tuple_B_2xUnpack=TupleAliasTsT[Unpack[Tuple[str]], Unpack[Tuple[int]], object]
self.assertEqual(nested_tuple_B_1xUnpack, nested_tuple_bare)
self.assertEqual(nested_tuple_B_1xUnpack, nested_tuple_B_2xUnpack)
self.assertNotEqual(invalid_nested_tuple, nested_tuple_B_1xUnpack)
Traceback:
TupleAliasTs[str]
~~~~~~~~~~~~^^^^^File"/home/me/test/envs/python3.11/lib/python3.11/typing.py", line379, ininnerreturnfunc(*args, **kwds)
^^^^^^^^^^^^^^^^^^^File"/home/me/test/envs/python3.11/lib/python3.11/typing.py", line1431, in__getitem__new_args=self._determine_new_args(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/home/me/test/envs/python3.11/lib/python3.11/typing.py", line1462, in_determine_new_argsreturntuple(self._make_substitution(self.__args__, new_arg_by_param))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/home/me/test/envs/python3.11/lib/python3.11/typing.py", line1486, in_make_substitutionnew_arg=old_arg[tuple(subargs)]
~~~~~~~^^^^^^^^^^^^^^^^File"/home/me/test/envs/python3.11/lib/python3.11/typing.py", line379, ininnerreturnfunc(*args, **kwds)
^^^^^^^^^^^^^^^^^^^File"/home/me/test/envs/python3.11/lib/python3.11/typing.py", line1431, in__getitem__new_args=self._determine_new_args(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/home/me/test/envs/python3.11/lib/python3.11/typing.py", line1462, in_determine_new_argsreturntuple(self._make_substitution(self.__args__, new_arg_by_param))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/home/me/test/envs/python3.11/lib/python3.11/typing.py", line1474, in_make_substitutionnew_arg=substfunc(new_arg_by_param[old_arg])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/home/me/test/envs/python3.11/lib/python3.11/typing.py", line1103, in__typing_subst__raiseTypeError("Substitution of bare TypeVarTuple is not supported")
TypeError: SubstitutionofbareTypeVarTupleisnotsupported
The text was updated successfully, but these errors were encountered:
I've written some tests to test nesting of Unpack with TypeAliasTypes, which causes
TypeError: Substitution of bare TypeVarTuple is not supported
during the recursive substitution.This is currently only relevant for 3.11 as for lower versions Issue #103 needs to be addressed first.
Traceback:
The text was updated successfully, but these errors were encountered: