@@ -461,7 +461,7 @@ class Starship:
461
461
be used with isinstance() or issubclass().
462
462
"""
463
463
item = _type_check (parameters , f'{ self } accepts only single type.' )
464
- return _GenericAlias (self , (item ,), name = "ClassVar" )
464
+ return _GenericAlias (self , (item ,))
465
465
466
466
@_SpecialForm
467
467
def Final (self , parameters ):
@@ -482,7 +482,7 @@ class FastConnector(Connection):
482
482
There is no runtime checking of these properties.
483
483
"""
484
484
item = _type_check (parameters , f'{ self } accepts only single type.' )
485
- return _GenericAlias (self , (item ,), name = "Final" )
485
+ return _GenericAlias (self , (item ,))
486
486
487
487
@_SpecialForm
488
488
def Union (self , parameters ):
@@ -520,12 +520,9 @@ def Union(self, parameters):
520
520
parameters = _remove_dups_flatten (parameters )
521
521
if len (parameters ) == 1 :
522
522
return parameters [0 ]
523
-
524
523
if len (parameters ) == 2 and type (None ) in parameters :
525
- name = "Optional"
526
- else :
527
- name = "Union"
528
- return _UnionGenericAlias (self , parameters , name = name )
524
+ return _UnionGenericAlias (self , parameters , name = "Optional" )
525
+ return _UnionGenericAlias (self , parameters )
529
526
530
527
@_SpecialForm
531
528
def Optional (self , parameters ):
@@ -570,7 +567,7 @@ def open_helper(file: str, mode: MODE) -> str:
570
567
except TypeError : # unhashable parameters
571
568
pass
572
569
573
- return _LiteralGenericAlias (self , parameters , name = "Literal" )
570
+ return _LiteralGenericAlias (self , parameters )
574
571
575
572
576
573
@_SpecialForm
@@ -609,7 +606,7 @@ def Concatenate(self, parameters):
609
606
"ParamSpec variable." )
610
607
msg = "Concatenate[arg, ...]: each arg must be a type."
611
608
parameters = tuple (_type_check (p , msg ) for p in parameters )
612
- return _ConcatenateGenericAlias (self , parameters , name = "Concatenate" )
609
+ return _ConcatenateGenericAlias (self , parameters )
613
610
614
611
615
612
@_SpecialForm
@@ -657,7 +654,7 @@ def is_str(val: Union[str, float]):
657
654
PEP 647 (User-Defined Type Guards).
658
655
"""
659
656
item = _type_check (parameters , f'{ self } accepts only single type.' )
660
- return _GenericAlias (self , (item ,), name = "TypeGuard" )
657
+ return _GenericAlias (self , (item ,))
661
658
662
659
663
660
class ForwardRef (_Final , _root = True ):
@@ -962,7 +959,7 @@ def __mro_entries__(self, bases):
962
959
963
960
def __getattr__ (self , attr ):
964
961
if attr in {'__name__' , '__qualname__' }:
965
- return self ._name
962
+ return self ._name or self . __origin__ . __name__
966
963
967
964
# We are careful for copy and pickle.
968
965
# Also for simplicity we just don't relay all dunder names
0 commit comments