@@ -453,7 +453,7 @@ class Starship:
453
453
be used with isinstance() or issubclass().
454
454
"""
455
455
item = _type_check (parameters , f'{ self } accepts only single type.' )
456
- return _GenericAlias (self , (item ,), name = "ClassVar" )
456
+ return _GenericAlias (self , (item ,))
457
457
458
458
@_SpecialForm
459
459
def Final (self , parameters ):
@@ -474,7 +474,7 @@ class FastConnector(Connection):
474
474
There is no runtime checking of these properties.
475
475
"""
476
476
item = _type_check (parameters , f'{ self } accepts only single type.' )
477
- return _GenericAlias (self , (item ,), name = "Final" )
477
+ return _GenericAlias (self , (item ,))
478
478
479
479
@_SpecialForm
480
480
def Union (self , parameters ):
@@ -512,12 +512,9 @@ def Union(self, parameters):
512
512
parameters = _remove_dups_flatten (parameters )
513
513
if len (parameters ) == 1 :
514
514
return parameters [0 ]
515
-
516
515
if len (parameters ) == 2 and type (None ) in parameters :
517
- name = "Optional"
518
- else :
519
- name = "Union"
520
- return _UnionGenericAlias (self , parameters , name = name )
516
+ return _UnionGenericAlias (self , parameters , name = "Optional" )
517
+ return _UnionGenericAlias (self , parameters )
521
518
522
519
@_SpecialForm
523
520
def Optional (self , parameters ):
@@ -562,7 +559,7 @@ def open_helper(file: str, mode: MODE) -> str:
562
559
except TypeError : # unhashable parameters
563
560
pass
564
561
565
- return _LiteralGenericAlias (self , parameters , name = "Literal" )
562
+ return _LiteralGenericAlias (self , parameters )
566
563
567
564
568
565
@_SpecialForm
@@ -601,7 +598,7 @@ def Concatenate(self, parameters):
601
598
"ParamSpec variable." )
602
599
msg = "Concatenate[arg, ...]: each arg must be a type."
603
600
parameters = tuple (_type_check (p , msg ) for p in parameters )
604
- return _ConcatenateGenericAlias (self , parameters , name = "Concatenate" )
601
+ return _ConcatenateGenericAlias (self , parameters )
605
602
606
603
607
604
@_SpecialForm
@@ -649,7 +646,7 @@ def is_str(val: Union[str, float]):
649
646
PEP 647 (User-Defined Type Guards).
650
647
"""
651
648
item = _type_check (parameters , f'{ self } accepts only single type.' )
652
- return _GenericAlias (self , (item ,), name = "TypeGuard" )
649
+ return _GenericAlias (self , (item ,))
653
650
654
651
655
652
class ForwardRef (_Final , _root = True ):
@@ -960,7 +957,7 @@ def __mro_entries__(self, bases):
960
957
961
958
def __getattr__ (self , attr ):
962
959
if attr in {'__name__' , '__qualname__' }:
963
- return self ._name
960
+ return self ._name or self . __origin__ . __name__
964
961
965
962
# We are careful for copy and pickle.
966
963
# Also for simplicity we just don't relay all dunder names
0 commit comments