Skip to content

Detect invalid overrides of instance variables with class variables, and vice versa #3093

@sharkdp

Description

@sharkdp

See this typing conformance test:

@dataclass
class DC6:
    x: int
    y: ClassVar[int] = 1


@dataclass
class DC7(DC6):
    # This should generate an error because a ClassVar cannot override
    # an instance variable of the same name.
    x: ClassVar[int]  # E

    # This should generate an error because an instance variable cannot
    # override a class variable of the same name.
    y: int  # E

This isn't actually specific to dataclasses, and should be implemented as a general Liskov check. This is also listed in #2158, but I wanted to have a separate issue that we can label as conformance / prioritize independently.

Metadata

Metadata

Assignees

Labels

conformancedataclassesIssues relating to dataclasses and dataclass_transformtyping semanticstyping-module features, spec compliance, etc

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions