Skip to content

Commit ce659ac

Browse files
committed
Do not consider unknown runtime type incompatible for consistency
1 parent 3471156 commit ce659ac

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mypy/stubtest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,18 +1268,20 @@ def verify_var(
12681268
runtime_type = get_mypy_type_of_runtime_value(runtime.value)
12691269
if runtime_type is not None and is_subtype_helper(runtime_type, stub.type):
12701270
should_error = False
1271-
# We always allow setting the stub value to ...
1271+
# We always allow setting the stub value to Ellipsis (...), but use
1272+
# _value_ type as a fallback if given. If a member is ... and _value_
1273+
# type is given, all runtime types should be assignable to _value_.
12721274
proper_type = mypy.types.get_proper_type(stub.type)
12731275
if (
12741276
isinstance(proper_type, mypy.types.Instance)
12751277
and proper_type.type.fullname in mypy.types.ELLIPSIS_TYPE_NAMES
12761278
):
12771279
value_t = stub.info.get("_value_")
1278-
if value_t is None or value_t.type is None:
1280+
if value_t is None or value_t.type is None or runtime_type is None:
12791281
should_error = False
1280-
elif runtime_type is not None and is_subtype_helper(runtime_type, value_t.type):
1282+
elif is_subtype_helper(runtime_type, value_t.type):
12811283
should_error = False
1282-
elif runtime_type is not None:
1284+
else:
12831285
note = " (incompatible '_value_')"
12841286

12851287
if should_error:

0 commit comments

Comments
 (0)