From 236b90b2cefb6e074ddf620cca8b56c94937e0d3 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 21 Jan 2024 20:43:18 -0800 Subject: [PATCH 1/3] Add support for setting enum members to "..." Unblock python/typeshed#11299 --- mypy/stubtest.py | 3 +++ mypy/test/teststubtest.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index 6061e98bd7cd3..9b9599ce9f8e4 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -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( diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py index c0bb2eb6f9da1..3f231d8afbccd 100644 --- a/mypy/test/teststubtest.py +++ b/mypy/test/teststubtest.py @@ -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): From 01eac125068e0f8642fa6d1d35107ae48157ae80 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 04:44:32 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/stubtest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index 9b9599ce9f8e4..e84d08df1df28 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -1094,7 +1094,10 @@ def verify_var( 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": + if ( + isinstance(stub.type, mypy.types.Instance) + and stub.type.type.fullname == "builtins.ellipsis" + ): should_error = False if should_error: From b52314dc5cdc7e103e21e0e95a97f99c22b639f0 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 21 Jan 2024 21:11:22 -0800 Subject: [PATCH 3/3] be proper --- mypy/stubtest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index e84d08df1df28..9a038105dc82e 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -1094,9 +1094,10 @@ def verify_var( 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(stub.type, mypy.types.Instance) - and stub.type.type.fullname == "builtins.ellipsis" + isinstance(proper_type, mypy.types.Instance) + and proper_type.type.fullname == "builtins.ellipsis" ): should_error = False