Skip to content

False uninitialized-instance-variable for metaclass attributes supplied in class bodies #5278

Open

Description

@adamtheturtle

Describe the bug

Instances of this metaclass are class objects. Their attribute is provided by the class namespace passed to type.__new__; it is present before the class is used.

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

class Metadata(type):
    label: str

class Example(metaclass=Metadata):
    label = "example"

def read_label(cls: Metadata) -> str:
    return cls.label

assert read_label(Example) == "example"

Commands

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

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

Pyrefly 1.4.0 output

Instance attribute `label` 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