@@ -421,11 +421,11 @@ def __new__(cls, *args, **kwargs):
421
421
raise TypeError ("Callable must be used as "
422
422
"Callable[[arg, ...], result]." )
423
423
_typ , _args = args
424
- if not isinstance (_args , tuple ) or len (_args ) != 2 :
424
+ if not isinstance (_args , ( tuple , type (...)) ) or len (_args ) != 2 :
425
425
raise TypeError ("Callable must be used as "
426
426
"Callable[[arg, ...], result]." )
427
427
t_args , t_result = _args
428
- if not isinstance (t_args , list ):
428
+ if not isinstance (t_args , ( list , type (...)) ):
429
429
raise TypeError ("Callable must be used as "
430
430
"Callable[[arg, ...], result]." )
431
431
@@ -440,12 +440,27 @@ def __new__(cls, *args, **kwargs):
440
440
def __init__ (self , * args , ** kwargs ):
441
441
pass
442
442
443
+ def __eq__ (self , other ):
444
+ if not isinstance (other , GenericAlias ):
445
+ return NotImplemented
446
+ return (self .__origin__ == other .__origin__
447
+ and self .__args__ == other .__args__ )
448
+
449
+ def __hash__ (self ):
450
+ return super ().__hash__ ()
451
+
443
452
def __repr__ (self ):
444
453
t_args = self .__args__ [:- 1 ]
445
454
t_result = self .__args__ [- 1 ]
446
- return f"{ _type_repr (self .__origin__ )} " \
447
- f"[[{ ', ' .join (_type_repr (a ) for a in t_args )} ], " \
448
- f"{ _type_repr (t_result )} ]"
455
+
456
+ orig = _type_repr (self .__origin__ )
457
+ args = f"{ ', ' .join (_type_repr (a ) for a in t_args )} "
458
+ result = _type_repr (t_result )
459
+
460
+ if not isinstance (t_args [0 ], type (...)):
461
+ args = f"[{ args } ]"
462
+
463
+ return f"{ orig } [{ args } , { result } ]"
449
464
450
465
451
466
def _type_repr (obj ):
0 commit comments