-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
Description
Bug Report
I expect to be able to use typing.Self for classmethods of an Enum subclass, but mypy fails the type check for such methods.
To Reproduce
https://mypy-play.net/?mypy=master&python=3.12&gist=9f529a65422ee83aba0312c91e74a935
from enum import *
from typing import *
class Foo(Enum):
BAR = "bar"
@classmethod
def get_bar(cls) -> Self:
return cls.BARExpected Behavior
Type checking should pass.
Actual Behavior
I get the following error:
main.py:9: error: Incompatible return value type (got "Foo", expected "Self") [return-value]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.13.0, 1.14.0, master branch
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.12, 3.13
Hnasar