@@ -1673,7 +1673,9 @@ class Movie(TypedDict):
16731673        """ )
16741674
16751675
1676- if  sys .version_info [:2 ] >=  (3 , 9 ):
1676+ if  hasattr (typing , "Unpack" ):  # 3.11+ 
1677+     Unpack  =  typing .Unpack 
1678+ elif  sys .version_info [:2 ] >=  (3 , 9 ):
16771679    class  _UnpackSpecialForm (typing ._SpecialForm , _root = True ):
16781680        def  __repr__ (self ):
16791681            return  'typing_extensions.'  +  self ._name 
@@ -1729,84 +1731,87 @@ def _is_unpack(obj):
17291731        return  isinstance (obj , _UnpackAlias )
17301732
17311733
1732- class  TypeVarTuple :
1733-     """Type variable tuple. 
1734+ if  hasattr (typing , "TypeVarTuple" ):  # 3.11+ 
1735+     TypeVarTuple  =  typing .TypeVarTuple 
1736+ else :
1737+     class  TypeVarTuple :
1738+         """Type variable tuple. 
17341739
1735-     Usage:: 
1740+          Usage:: 
17361741
1737-         Ts = TypeVarTuple('Ts') 
1742+              Ts = TypeVarTuple('Ts') 
17381743
1739-     In the same way that a normal type variable is a stand-in for a single 
1740-     type such as ``int``, a type variable *tuple* is a stand-in for a *tuple* type such as  
1741-     ``Tuple[int, str]``. 
1744+          In the same way that a normal type variable is a stand-in for a single 
1745+          type such as ``int``, a type variable *tuple* is a stand-in for a *tuple* 
1746+         type such as  ``Tuple[int, str]``. 
17421747
1743-     Type variable tuples can be used in ``Generic`` declarations. 
1744-     Consider the following example:: 
1748+          Type variable tuples can be used in ``Generic`` declarations. 
1749+          Consider the following example:: 
17451750
1746-         class Array(Generic[*Ts]): ... 
1751+              class Array(Generic[*Ts]): ... 
17471752
1748-     The ``Ts`` type variable tuple here behaves like ``tuple[T1, T2]``, 
1749-     where ``T1`` and ``T2`` are type variables. To use these type variables 
1750-     as type parameters of ``Array``, we must *unpack* the type variable tuple using 
1751-     the star operator: ``*Ts``. The signature of ``Array`` then behaves 
1752-     as if we had simply written ``class Array(Generic[T1, T2]): ...``. 
1753-     In contrast to ``Generic[T1, T2]``, however, ``Generic[*Shape]`` allows 
1754-     us to parameterise the class with an *arbitrary* number of type parameters. 
1753+          The ``Ts`` type variable tuple here behaves like ``tuple[T1, T2]``, 
1754+          where ``T1`` and ``T2`` are type variables. To use these type variables 
1755+          as type parameters of ``Array``, we must *unpack* the type variable tuple using 
1756+          the star operator: ``*Ts``. The signature of ``Array`` then behaves 
1757+          as if we had simply written ``class Array(Generic[T1, T2]): ...``. 
1758+          In contrast to ``Generic[T1, T2]``, however, ``Generic[*Shape]`` allows 
1759+          us to parameterise the class with an *arbitrary* number of type parameters. 
17551760
1756-     Type variable tuples can be used anywhere a normal ``TypeVar`` can. 
1757-     This includes class definitions, as shown above, as well as function 
1758-     signatures and variable annotations:: 
1761+          Type variable tuples can be used anywhere a normal ``TypeVar`` can. 
1762+          This includes class definitions, as shown above, as well as function 
1763+          signatures and variable annotations:: 
17591764
1760-         class Array(Generic[*Ts]): 
1765+              class Array(Generic[*Ts]): 
17611766
1762-             def __init__(self, shape: Tuple[*Ts]): 
1763-                 self._shape: Tuple[*Ts] = shape 
1767+                  def __init__(self, shape: Tuple[*Ts]): 
1768+                      self._shape: Tuple[*Ts] = shape 
17641769
1765-             def get_shape(self) -> Tuple[*Ts]: 
1766-                 return self._shape 
1770+                  def get_shape(self) -> Tuple[*Ts]: 
1771+                      return self._shape 
17671772
1768-         shape = (Height(480), Width(640)) 
1769-         x: Array[Height, Width] = Array(shape) 
1770-         y = abs(x)  # Inferred type is Array[Height, Width] 
1771-         z = x + x   #        ...    is Array[Height, Width] 
1772-         x.get_shape()  #     ...    is tuple[Height, Width] 
1773+              shape = (Height(480), Width(640)) 
1774+              x: Array[Height, Width] = Array(shape) 
1775+              y = abs(x)  # Inferred type is Array[Height, Width] 
1776+              z = x + x   #        ...    is Array[Height, Width] 
1777+              x.get_shape()  #     ...    is tuple[Height, Width] 
17731778
1774-     """ 
1779+          """ 
17751780
1776-     # Trick Generic __parameters__. 
1777-     __class__  =  typing .TypeVar 
1781+          # Trick Generic __parameters__. 
1782+          __class__  =  typing .TypeVar 
17781783
1779-     def  __iter__ (self ):
1780-         yield  self .__unpacked__ 
1784+          def  __iter__ (self ):
1785+              yield  self .__unpacked__ 
17811786
1782-     def  __init__ (self , name ):
1783-         self .__name__  =  name 
1787+          def  __init__ (self , name ):
1788+              self .__name__  =  name 
17841789
1785-         # for pickling: 
1786-         try :
1787-             def_mod  =  sys ._getframe (1 ).f_globals .get ('__name__' , '__main__' )
1788-         except  (AttributeError , ValueError ):
1789-             def_mod  =  None 
1790-         if  def_mod  !=  'typing_extensions' :
1791-             self .__module__  =  def_mod 
1790+              # for pickling: 
1791+              try :
1792+                  def_mod  =  sys ._getframe (1 ).f_globals .get ('__name__' , '__main__' )
1793+              except  (AttributeError , ValueError ):
1794+                  def_mod  =  None 
1795+              if  def_mod  !=  'typing_extensions' :
1796+                  self .__module__  =  def_mod 
17921797
1793-         self .__unpacked__  =  Unpack [self ]
1798+              self .__unpacked__  =  Unpack [self ]
17941799
1795-     def  __repr__ (self ):
1796-         return  self .__name__ 
1800+          def  __repr__ (self ):
1801+              return  self .__name__ 
17971802
1798-     def  __hash__ (self ):
1799-         return  object .__hash__ (self )
1803+          def  __hash__ (self ):
1804+              return  object .__hash__ (self )
18001805
1801-     def  __eq__ (self , other ):
1802-         return  self  is  other 
1806+          def  __eq__ (self , other ):
1807+              return  self  is  other 
18031808
1804-     def  __reduce__ (self ):
1805-         return  self .__name__ 
1809+          def  __reduce__ (self ):
1810+              return  self .__name__ 
18061811
1807-     def  __init_subclass__ (self , * args , ** kwds ):
1808-         if  '_root'  not  in kwds :
1809-             raise  TypeError ("Cannot subclass special typing classes" )
1812+          def  __init_subclass__ (self , * args , ** kwds ):
1813+              if  '_root'  not  in kwds :
1814+                  raise  TypeError ("Cannot subclass special typing classes" )
18101815
18111816
18121817if  hasattr (typing , "reveal_type" ):
0 commit comments