Skip to content

False uninitialized-instance-variable for annotated Enum payloads #5277

Open

Description

@adamtheturtle

Describe the bug

Enum initializes _value_ when constructing its members. An explicit _value_ annotation should not require a handwritten initializer.

Reproduced with Pyrefly 1.4.0 and CPython 3.14.8 on macOS. Pyrefly 1.3.2 accepts the same example under --preset all.

Reproducer

from enum import Enum

class Format(Enum):
    _value_: str
    TEXT = "text"

    def render(self) -> str:
        return self._value_

assert Format.TEXT.render() == "text"

Commands

uvx --from pyrefly==1.3.2 pyrefly check --preset all enum_payload.py
uvx --from pyrefly==1.4.0 pyrefly check --preset all enum_payload.py
python enum_payload.py

The runtime assertion passes. The configuration only sets preset = "all" and python-version = "3.14".

Pyrefly 1.4.0 output

Instance attribute `_value_` is declared but never initialized [uninitialized-instance-variable]

Mypy 2.4.0 (strict, without project plugins) and Pyright 1.1.414 accept this example.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions