@@ -1773,7 +1773,7 @@ class _ConcatenateGenericAlias(list):
1773
1773
# Flag in 3.8.
1774
1774
_special = False
1775
1775
1776
- def __init__ (self , origin , args ):
1776
+ def __init__ (self , origin , args , _typevar_types = ( TypeVar , ParamSpec ), _paramspec_tvars = True ):
1777
1777
super ().__init__ (args )
1778
1778
self .__origin__ = origin
1779
1779
self .__args__ = args
@@ -1795,28 +1795,30 @@ def __parameters__(self):
1795
1795
return tuple (
1796
1796
tp for tp in self .__args__ if isinstance (tp , (typing .TypeVar , ParamSpec ))
1797
1797
)
1798
+ # 3.10+
1799
+ else :
1800
+ _ConcatenateGenericAlias = typing ._ConcatenateGenericAlias # noqa: F811
1798
1801
1799
-
1800
- # 3.8-3.9
1802
+ # 3.8-3.10
1801
1803
@typing ._tp_cache
1802
1804
def _concatenate_getitem (self , parameters ):
1803
1805
if parameters == ():
1804
1806
raise TypeError ("Cannot take a Concatenate of no types." )
1805
1807
if not isinstance (parameters , tuple ):
1806
1808
parameters = (parameters ,)
1807
- if not isinstance (parameters [- 1 ], ParamSpec ):
1809
+ if not ( parameters [ - 1 ] is ... or isinstance (parameters [- 1 ], ParamSpec ) ):
1808
1810
raise TypeError ("The last parameter to Concatenate should be a "
1809
- "ParamSpec variable." )
1811
+ "ParamSpec variable or ellipsis ." )
1810
1812
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 )
1813
1817
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 ):
1817
1820
Concatenate = typing .Concatenate
1818
- _ConcatenateGenericAlias = typing ._ConcatenateGenericAlias
1819
- # 3.9
1821
+ # 3.9-3.10
1820
1822
elif sys .version_info [:2 ] >= (3 , 9 ):
1821
1823
@_ExtensionsSpecialForm
1822
1824
def Concatenate (self , parameters ):
0 commit comments