-
The following commit: 7888d1c refering to this issue: #5092 made it so that the following would evaluate the value to Code sample in pyright playground from enum import Enum, EnumMeta, IntEnum
from typing import Any, Literal, assert_type
class ChoicesMeta(EnumMeta):
...
class IntegerChoicesWithMeta(Enum, metaclass=ChoicesMeta):
@property
def value(self) -> int: ...
class IntegerChoicesWithoutMeta(Enum):
@property
def value(self) -> int: ...
class MyEnumWithMeta(IntegerChoicesWithMeta):
A = 1
class MyEnumWithoutMeta(IntegerChoicesWithoutMeta):
A = 1
assert_type(MyEnumWithMeta.A.value, Any)
assert_type(MyEnumWithoutMeta.A.value, Literal[1])
def fun(with_meta: MyEnumWithMeta, without_meta: MyEnumWithoutMeta) -> None:
assert_type(with_meta.value, Any)
assert_type(without_meta.value, Literal[1]) Which could make sense as said in the linked issue, the metaclass (in the case of the Django Would it be possible to infer For some context I'm trying to improve the stubs of the Django enums here: typeddjango/django-stubs#2162. I had to go through the internals of Python (and the extra magic Django is doing) enums -- I believe you had to do the same for the draft chapter in the spec -- and was surprised by how much metaclasses (and meta programming) are pushed to their limits. So I would understand if this request is not accepted |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, this sounds reasonable. It's also consistent with mypy's current behavior. The next version of pyright will include this change. |
Beta Was this translation helpful? Give feedback.
Yes, this sounds reasonable. It's also consistent with mypy's current behavior.
The next version of pyright will include this change.