Skip to content

False attr-defined error when dataclass property mirrors initvar #13110

Closed as not planned
@joshuafishman

Description

@joshuafishman

Bug Report

#12046 describes one false positive in this case. However, any time the mirrored attribute is referenced also raises a false positive attribute error. Short of ignoring every reference to the offending attribute, I don't see a workaround.

To Reproduce

from dataclasses import dataclass, InitVar


@dataclass
class Baz:
    foo: InitVar[int]

    @property  # type: ignore
    def foo(self) -> int:
        return 0


print(Baz(0).foo)

Actual Behavior

error: "Baz" has no attribute "foo" [attr-defined]

Your Environment

  • Mypy version used: 0.910
  • Python version used: 3.9
  • Operating system and version: Ubuntu 20.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions