Skip to content

False [uninitialized-instance-variable] error in frozen dataclass #5326

Open

Description

@Ravencentric

Describe the Bug

Pyrefly version: 1.4.0

from dataclasses import dataclass
from pathlib import PurePosixPath


@dataclass(frozen=True, slots=True, init=False)
class File:
	# ERROR sandbox.py:7:5-10: Instance attribute `inner` is declared but never initialized [uninitialized-instance-variable]
    inner: tuple[PurePosixPath, int]

    def __init__(self, path: str, /, *, size: int) -> None:
        object.__setattr__(self, "inner", (PurePosixPath(path), size))

    @property
    def name(self) -> str:
        path, _ = self.inner
        return path.name

    @property
    def size(self) -> int:
        _, size = self.inner
        return size

object.__setattr__ in frozen dataclasses is not unheard of and it's pretty useful when I want to make some changes in __init__ but have the object frozen after.

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.jZXNasMwEIRfZWkOtoux7oZATz37XhdjWpEaimUkuTR5-szqJ7EIURII2PLuzgjtt8qOzBz2Pc7bBQVYY0C3atkpM_13WOeg-L_SWyLvJOc9Hw667ldZE555D_v3EW1WcYrnlV23_OrafMZcbsmuIPgj0eJs-xnV7qDNZt2QqEnU9Ar16QTEkLlp1ZDOP49YMwxG2tFafSmE82In_UtNZWKjZInKF67cLmK9t0WrBWP8uPXHLe9KOn0YS-S5Vk0gwo8cL7n5HhDlsIYrPZRjV1c5bDuRG7ztR3Icc9v9O-r8AoVGwtwHNocVtwtwaPp5h4tF0o-1i2mFiOlKH4Scxbf6MiLJEMSgj3_j5O6stBwpR6tB2Qx2i5Y4OLcEep8CsfAcFjkMC6YQEVmyzg

(Only applicable for extension issues) IDE Information

No response

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