Skip to content

Commit df7e9ad

Browse files
committed
Tidy up
1 parent 5010db7 commit df7e9ad

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

mypy/stubtest.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,15 +1017,15 @@ def verify_typealias(
10171017
stub_desc=f"Type alias for: {stub_target}"
10181018
)
10191019
return
1020+
runtime_type = get_origin(runtime) or runtime
10201021
if isinstance(stub_target, mypy.types.Instance):
1021-
runtime_type = get_origin(runtime) or runtime
10221022
if not isinstance(runtime_type, type):
10231023
yield Error(
10241024
object_path, "is inconsistent: runtime is not a type", stub, runtime,
10251025
stub_desc=f"Type alias for: {stub_target}"
10261026
)
10271027
return
1028-
# Don't test the fullname,
1028+
# Don't test the fullname;
10291029
# stubs can sometimes be in different modules to the runtime for various reasons
10301030
# (e.g. we want compatibility between collections.abc and typing, etc.)
10311031
try:
@@ -1043,14 +1043,14 @@ def verify_typealias(
10431043
)
10441044
return
10451045
if isinstance(stub_target, mypy.types.UnionType):
1046+
# could check Union contents here...
10461047
if sys.version_info >= (3, 10) and isinstance(runtime, types.UnionType):
10471048
return
1048-
if not getattr(runtime, "__origin__", None) is Union:
1049+
if runtime_type is not Union:
10491050
yield Error(object_path, "is not a Union", stub, runtime, stub_desc=str(stub_target))
1050-
# could check Union contents here...
10511051
return
10521052
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__", ()):
10541054
yield Error(
10551055
object_path, "is not a subclass of tuple", stub, runtime,
10561056
stub_desc=f"Type alias for: {stub_target}"
@@ -1060,13 +1060,12 @@ def verify_typealias(
10601060
if isinstance(stub_target, mypy.types.AnyType):
10611061
return
10621062
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
10701069
yield Error(
10711070
object_path, "is not a recognised type alias", stub, runtime,
10721071
stub_desc=f"Type alias for: {stub_target}"

0 commit comments

Comments
 (0)