Skip to content

Commit

Permalink
Add support for setting enum members to "..."
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Jan 22, 2024
1 parent 75b68fa commit 236b90b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,9 @@ 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 ...
if isinstance(stub.type, mypy.types.Instance) and stub.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 236b90b

Please sign in to comment.