-
Notifications
You must be signed in to change notification settings - Fork 276
Closed
Closed
Copy link
Labels
Description
Describe the Bug
Pyrefly incorrectly reports that enum members of mixed-type enums (inheriting from both a primitive type and Enum) don't have a value attribute.
Expected Behavior
Mixed-type enum members should be recognized as having the value attribute, as they inherit from Enum.
Actual Behavior
Pyrefly reports errors:
Object of class 'str' has no attribute 'value'
Object of class 'int' has no attribute 'value'
Minimal Reproduction Case
from enum import Enum
class StrEnum(str, Enum):
FOO = "FOO"
DEFAULT = "DEFAULT"
@classmethod
def normalize(cls, val: str) -> str:
try:
return cls(val).value # Pyrefly error: Object of class `str` has no attribute `value`
except ValueError:
return cls.DEFAULT.value
class IntEnum(int, Enum):
FOO = 1
DEFAULT = 0
@classmethod
def normalize(cls, val: int) -> int:
try:
return cls(val).value # Pyrefly error: Object of class `int` has no attribute `value`
except ValueError:
return cls.DEFAULT.valueContext
- cls(val) returns an enum member (e.g., StrEnum.FOO)
- This code works correctly at runtime and passes other type checkers like mypy and pyright
- python version is 3.12.6
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Reactions are currently unavailable