@@ -287,6 +287,7 @@ def __init_subclass__(self, /, *args, **kwds):
287287 if '_root' not in kwds :
288288 raise TypeError ("Cannot subclass special typing classes" )
289289
290+
290291class _Immutable :
291292 """Mixin to indicate that object should not be copied."""
292293
@@ -370,8 +371,7 @@ def __getitem__(self, parameters):
370371 raise TypeError (f"{ self } is not subscriptable" )
371372
372373
373- Any = _SpecialForm ('Any' , doc =
374- """Special type indicating an unconstrained type.
374+ Any = _SpecialForm ('Any' , doc = """Special type indicating an unconstrained type.
375375
376376 - Any is compatible with every type.
377377 - Any assumed to have all methods.
@@ -382,8 +382,7 @@ def __getitem__(self, parameters):
382382 or class checks.
383383 """ )
384384
385- NoReturn = _SpecialForm ('NoReturn' , doc =
386- """Special type indicating functions that never return.
385+ NoReturn = _SpecialForm ('NoReturn' , doc = """Special type indicating functions that never return.
387386 Example::
388387
389388 from typing import NoReturn
@@ -395,8 +394,7 @@ def stop() -> NoReturn:
395394 will fail in static type checkers.
396395 """ )
397396
398- ClassVar = _SpecialForm ('ClassVar' , doc =
399- """Special type construct to mark class variables.
397+ ClassVar = _SpecialForm ('ClassVar' , doc = """Special type construct to mark class variables.
400398
401399 An annotation wrapped in ClassVar indicates that a given
402400 attribute is intended to be used as a class variable and
@@ -412,8 +410,7 @@ class Starship:
412410 be used with isinstance() or issubclass().
413411 """ )
414412
415- Final = _SpecialForm ('Final' , doc =
416- """Special typing construct to indicate final names to type checkers.
413+ Final = _SpecialForm ('Final' , doc = """Special typing construct to indicate final names to type checkers.
417414
418415 A final name cannot be re-assigned or overridden in a subclass.
419416 For example:
@@ -430,8 +427,7 @@ class FastConnector(Connection):
430427 There is no runtime checking of these properties.
431428 """ )
432429
433- Union = _SpecialForm ('Union' , doc =
434- """Union type; Union[X, Y] means either X or Y.
430+ Union = _SpecialForm ('Union' , doc = """Union type; Union[X, Y] means either X or Y.
435431
436432 To define a union, use e.g. Union[int, str]. Details:
437433 - The arguments must be types and there must be at least one.
@@ -457,14 +453,12 @@ class FastConnector(Connection):
457453 - You can use Optional[X] as a shorthand for Union[X, None].
458454 """ )
459455
460- Optional = _SpecialForm ('Optional' , doc =
461- """Optional type.
456+ Optional = _SpecialForm ('Optional' , doc = """Optional type.
462457
463458 Optional[X] is equivalent to Union[X, None].
464459 """ )
465460
466- Literal = _SpecialForm ('Literal' , doc =
467- """Special typing form to define literal types (a.k.a. value types).
461+ Literal = _SpecialForm ('Literal' , doc = """Special typing form to define literal types (a.k.a. value types).
468462
469463 This form can be used to indicate to type checkers that the corresponding
470464 variable or function parameter has a value equivalent to the provided
@@ -601,7 +595,8 @@ def __init__(self, name, *constraints, bound=None,
601595 else :
602596 self .__bound__ = None
603597 try :
604- def_mod = sys ._getframe (1 ).f_globals .get ('__name__' , '__main__' ) # for pickling
598+ def_mod = sys ._getframe (1 ).f_globals .get (
599+ '__name__' , '__main__' ) # for pickling
605600 except (AttributeError , ValueError ):
606601 def_mod = None
607602 if def_mod != 'typing' :
@@ -643,6 +638,7 @@ def __reduce__(self):
643638 'type' : 'Type' ,
644639 'Set' : 'AbstractSet' }
645640
641+
646642def _is_dunder (attr ):
647643 return attr .startswith ('__' ) and attr .endswith ('__' )
648644
@@ -656,6 +652,7 @@ class _GenericAlias(_Final, _root=True):
656652 have 'name' always set. If 'inst' is False, then the alias can't be instantiated,
657653 this is used by e.g. typing.List and typing.Dict.
658654 """
655+
659656 def __init__ (self , origin , params , * , inst = True , special = False , name = None ):
660657 self ._inst = inst
661658 self ._special = special
@@ -786,7 +783,7 @@ def __reduce__(self):
786783 else :
787784 origin = self .__origin__
788785 if (origin is Callable and
789- not (len (self .__args__ ) == 2 and self .__args__ [0 ] is Ellipsis )):
786+ not (len (self .__args__ ) == 2 and self .__args__ [0 ] is Ellipsis )):
790787 args = list (self .__args__ [:- 1 ]), self .__args__ [- 1 ]
791788 else :
792789 args = tuple (self .__args__ )
@@ -799,6 +796,7 @@ class _VariadicGenericAlias(_GenericAlias, _root=True):
799796 """Same as _GenericAlias above but for variadic aliases. Currently,
800797 this is used only by special internal aliases: Tuple and Callable.
801798 """
799+
802800 def __getitem__ (self , params ):
803801 if self ._name != 'Callable' or not self ._special :
804802 return self .__getitem_inner__ (params )
@@ -989,7 +987,9 @@ def _allow_reckless_class_cheks():
989987 issubclass() on the whole MRO of a user class, which may contain protocols.
990988 """
991989 try :
992- return sys ._getframe (3 ).f_globals ['__name__' ] in ['abc' , 'functools' ]
990+ # XXX RUSTPYTHON: added _py_abc; I think CPython was fine because abc called
991+ # directly into the _abc builtin module, which wasn't in the frame stack
992+ return sys ._getframe (3 ).f_globals ['__name__' ] in ['abc' , 'functools' , '_py_abc' ]
993993 except (AttributeError , ValueError ): # For platforms without _getframe().
994994 return True
995995
@@ -1435,6 +1435,7 @@ class Other(Leaf): # Error reported by type checker
14351435def _alias (origin , params , inst = True ):
14361436 return _GenericAlias (origin , params , special = True , inst = inst )
14371437
1438+
14381439Hashable = _alias (collections .abc .Hashable , ()) # Not generic.
14391440Awaitable = _alias (collections .abc .Awaitable , T_co )
14401441Coroutine = _alias (collections .abc .Coroutine , (T_co , T_contra , V_co ))
@@ -1672,7 +1673,7 @@ def __new__(*args, **kwargs):
16721673 raise TypeError ('NamedTuple.__new__(): not enough arguments' )
16731674 cls , * args = args # allow the "cls" keyword be passed
16741675 if args :
1675- typename , * args = args # allow the "typename" keyword be passed
1676+ typename , * args = args # allow the "typename" keyword be passed
16761677 elif 'typename' in kwargs :
16771678 typename = kwargs .pop ('typename' )
16781679 import warnings
@@ -1683,7 +1684,7 @@ def __new__(*args, **kwargs):
16831684 "argument: 'typename'" )
16841685 if args :
16851686 try :
1686- fields , = args # allow the "fields" keyword be passed
1687+ fields , = args # allow the "fields" keyword be passed
16871688 except ValueError :
16881689 raise TypeError (f'NamedTuple.__new__() takes from 2 to 3 '
16891690 f'positional arguments but { len (args ) + 2 } '
@@ -1999,6 +2000,7 @@ class io:
19992000Pattern = _alias (stdlib_re .Pattern , AnyStr )
20002001Match = _alias (stdlib_re .Match , AnyStr )
20012002
2003+
20022004class re :
20032005 """Wrapper namespace for re type aliases."""
20042006
0 commit comments