Skip to content

False positive with @dataclass(frozen=True) and a ClassVar #2789

@sobolevn

Description

@sobolevn
import dataclasses
from typing import ClassVar

@dataclasses.dataclass(frozen=True)
class _Test:
    x: ClassVar[bool] = True
    def some(self) -> None:
        self.__class__.x = False

Produces:

» pyrefly check
 INFO Checking project configured at `pyproject.toml`
ERROR Cannot set field `x` [read-only]
  --> test.py:8:9
   |
23 |         self.__class__.x = False
   |         ^^^^^^^^^^^^^^^^
   |
  This field is a frozen dataclass member

However, this works in runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions