Skip to content

Commit

Permalink
stubtest: Add support for setting enum members to "..." (#16807)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Jan 22, 2024
1 parent 75b68fa commit 7eab8a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,13 @@ def verify_var(
runtime_type = get_mypy_type_of_runtime_value(runtime.value)
if runtime_type is not None and is_subtype_helper(runtime_type, stub.type):
should_error = False
# We always allow setting the stub value to ...
proper_type = mypy.types.get_proper_type(stub.type)
if (
isinstance(proper_type, mypy.types.Instance)
and proper_type.type.fullname == "builtins.ellipsis"
):
should_error = False

if should_error:
yield Error(
Expand Down
19 changes: 19 additions & 0 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,25 @@ def baz(x=Flags3(0)): pass
""",
error=None,
)
yield Case(
runtime="""
import enum
class SomeObject: ...
class WeirdEnum(enum.Enum):
a = SomeObject()
b = SomeObject()
""",
stub="""
import enum
class SomeObject: ...
class WeirdEnum(enum.Enum):
_value_: SomeObject
a = ...
b = ...
""",
error=None,
)
yield Case(
stub="""
class Flags4(enum.Flag):
Expand Down

0 comments on commit 7eab8a4

Please sign in to comment.