@@ -1017,15 +1017,15 @@ def verify_typealias(
1017
1017
stub_desc = f"Type alias for: { stub_target } "
1018
1018
)
1019
1019
return
1020
+ runtime_type = get_origin (runtime ) or runtime
1020
1021
if isinstance (stub_target , mypy .types .Instance ):
1021
- runtime_type = get_origin (runtime ) or runtime
1022
1022
if not isinstance (runtime_type , type ):
1023
1023
yield Error (
1024
1024
object_path , "is inconsistent: runtime is not a type" , stub , runtime ,
1025
1025
stub_desc = f"Type alias for: { stub_target } "
1026
1026
)
1027
1027
return
1028
- # Don't test the fullname,
1028
+ # Don't test the fullname;
1029
1029
# stubs can sometimes be in different modules to the runtime for various reasons
1030
1030
# (e.g. we want compatibility between collections.abc and typing, etc.)
1031
1031
try :
@@ -1043,14 +1043,14 @@ def verify_typealias(
1043
1043
)
1044
1044
return
1045
1045
if isinstance (stub_target , mypy .types .UnionType ):
1046
+ # could check Union contents here...
1046
1047
if sys .version_info >= (3 , 10 ) and isinstance (runtime , types .UnionType ):
1047
1048
return
1048
- if not getattr ( runtime , "__origin__" , None ) is Union :
1049
+ if runtime_type is not Union :
1049
1050
yield Error (object_path , "is not a Union" , stub , runtime , stub_desc = str (stub_target ))
1050
- # could check Union contents here...
1051
1051
return
1052
1052
if isinstance (stub_target , mypy .types .TupleType ):
1053
- if tuple not in getattr (runtime , "__mro__" , getattr ( get_origin ( runtime ), "__mro__" , () )):
1053
+ if tuple not in getattr (runtime_type , "__mro__" , ( )):
1054
1054
yield Error (
1055
1055
object_path , "is not a subclass of tuple" , stub , runtime ,
1056
1056
stub_desc = f"Type alias for: { stub_target } "
@@ -1060,13 +1060,12 @@ def verify_typealias(
1060
1060
if isinstance (stub_target , mypy .types .AnyType ):
1061
1061
return
1062
1062
if isinstance (stub_target , mypy .types .CallableType ):
1063
- callables = {typing .Callable , collections .abc .Callable }
1064
- if runtime in callables or get_origin (runtime ) in callables :
1065
- return
1066
- yield Error (
1067
- object_path , "is not a type alias for Callable" , stub , runtime ,
1068
- stub_desc = f"Type alias for: { stub_target } "
1069
- )
1063
+ if runtime_type is not collections .abc .Callable :
1064
+ yield Error (
1065
+ object_path , "is not a type alias for Callable" , stub , runtime ,
1066
+ stub_desc = f"Type alias for: { stub_target } "
1067
+ )
1068
+ return
1070
1069
yield Error (
1071
1070
object_path , "is not a recognised type alias" , stub , runtime ,
1072
1071
stub_desc = f"Type alias for: { stub_target } "
0 commit comments