Open
Description
In a method of a class derived from Flag, the type of self
appears to be unknown.
To Reproduce
import enum
class Foo(enum.Flag):
A = 1
B = 2
def names(self):
return [v.name for v in list(self.__class__) if self & v]
Expected Behavior
no errors
Actual Behavior
$ mypy --check-untyped-defs flag.py
flag.py:8: error: "object" has no attribute "name" [attr-defined]
flag.py:8: error: Unsupported operand types for & ("Foo" and "object") [operator]
Though I can resolve the error by annotating self
with typing_extensions.Self
, I'm not sure that should be necessary.
Your Environment
- Mypy version used: 1.2.0
- Python version used: 3.11.0