8
8
9
9
from abc import ABCMeta , abstractmethod
10
10
import sys
11
- import types
12
11
13
12
GenericAlias = type (list [int ])
13
+ EllipsisType = type (...)
14
+ def _f (): pass
15
+ FunctionType = type (_f )
16
+
14
17
15
18
__all__ = ["Awaitable" , "Coroutine" ,
16
19
"AsyncIterable" , "AsyncIterator" , "AsyncGenerator" ,
@@ -418,21 +421,22 @@ class _CallableGenericAlias(GenericAlias):
418
421
419
422
See :issue:`42195`.
420
423
"""
424
+
421
425
def __new__ (cls , * args , ** kwargs ):
422
426
if not isinstance (args , tuple ) or len (args ) != 2 :
423
427
raise TypeError ("Callable must be used as "
424
428
"Callable[[arg, ...], result]." )
425
429
_typ , _args = args
426
- if not isinstance (_args , (tuple , types . EllipsisType )) or len (_args ) != 2 :
430
+ if not isinstance (_args , (tuple , EllipsisType )) or len (_args ) != 2 :
427
431
raise TypeError ("Callable must be used as "
428
432
"Callable[[arg, ...], result]." )
429
433
t_args , t_result = _args
430
- if not isinstance (t_args , (list , types . EllipsisType )):
434
+ if not isinstance (t_args , (list , EllipsisType )):
431
435
raise TypeError ("Callable[args, result]: args must be a list. Got"
432
436
f" { _type_repr (t_args )} " )
433
437
434
438
ga_args = []
435
- for arg in args [ 1 ] :
439
+ for arg in _args :
436
440
if isinstance (arg , list ):
437
441
ga_args .extend (arg )
438
442
else :
@@ -459,7 +463,7 @@ def __repr__(self):
459
463
args = f"{ ', ' .join (_type_repr (a ) for a in t_args )} "
460
464
result = _type_repr (t_result )
461
465
462
- if not isinstance (t_args [0 ], types . EllipsisType ):
466
+ if not isinstance (t_args [0 ], EllipsisType ):
463
467
args = f"[{ args } ]"
464
468
465
469
return f"{ orig } [{ args } , { result } ]"
@@ -481,7 +485,7 @@ def _type_repr(obj):
481
485
return f'{ obj .__module__ } .{ obj .__qualname__ } '
482
486
if obj is ...:
483
487
return ('...' )
484
- if isinstance (obj , types . FunctionType ):
488
+ if isinstance (obj , FunctionType ):
485
489
return obj .__name__
486
490
return repr (obj )
487
491
0 commit comments