@@ -1773,7 +1773,7 @@ class _ConcatenateGenericAlias(list):
17731773 # Flag in 3.8.
17741774 _special = False
17751775
1776- def __init__ (self , origin , args ):
1776+ def __init__ (self , origin , args , _typevar_types = ( TypeVar , ParamSpec ), _paramspec_tvars = True ):
17771777 super ().__init__ (args )
17781778 self .__origin__ = origin
17791779 self .__args__ = args
@@ -1795,28 +1795,30 @@ def __parameters__(self):
17951795 return tuple (
17961796 tp for tp in self .__args__ if isinstance (tp , (typing .TypeVar , ParamSpec ))
17971797 )
1798+ # 3.10+
1799+ else :
1800+ _ConcatenateGenericAlias = typing ._ConcatenateGenericAlias # noqa: F811
17981801
1799-
1800- # 3.8-3.9
1802+ # 3.8-3.10
18011803@typing ._tp_cache
18021804def _concatenate_getitem (self , parameters ):
18031805 if parameters == ():
18041806 raise TypeError ("Cannot take a Concatenate of no types." )
18051807 if not isinstance (parameters , tuple ):
18061808 parameters = (parameters ,)
1807- if not isinstance (parameters [- 1 ], ParamSpec ):
1809+ if not ( parameters [ - 1 ] is ... or isinstance (parameters [- 1 ], ParamSpec ) ):
18081810 raise TypeError ("The last parameter to Concatenate should be a "
1809- "ParamSpec variable." )
1811+ "ParamSpec variable or ellipsis ." )
18101812 msg = "Concatenate[arg, ...]: each arg must be a type."
1811- parameters = tuple (typing ._type_check (p , msg ) for p in parameters )
1812- return _ConcatenateGenericAlias (self , parameters )
1813+ parameters = (* (typing ._type_check (p , msg ) for p in parameters [:- 1 ]), parameters [- 1 ])
1814+ return _ConcatenateGenericAlias (self , parameters ,
1815+ _typevar_types = (TypeVar , ParamSpec ),
1816+ _paramspec_tvars = True )
18131817
1814-
1815- # 3.10+
1816- if hasattr (typing , 'Concatenate' ):
1818+ # 3.11+; Concatenate does not accept ellipsis in 3.10
1819+ if hasattr (typing , 'Concatenate' ) and sys .version_info [:2 ] >= (3 , 11 ):
18171820 Concatenate = typing .Concatenate
1818- _ConcatenateGenericAlias = typing ._ConcatenateGenericAlias
1819- # 3.9
1821+ # 3.9-3.10
18201822elif sys .version_info [:2 ] >= (3 , 9 ):
18211823 @_ExtensionsSpecialForm
18221824 def Concatenate (self , parameters ):
0 commit comments