Skip to content

Detect when default value of dataclass field is mutable #10553

@erictraut

Description

@erictraut

The typing spec conformance suite was recently updated to validate that type checkers are detecting a case that generates a runtime exception when a dataclass field has a default value that is a mutable type.

@dataclass
class DC5:
    # This should generate an error because a default value of
    # type list, dict, or set generate a runtime error.
    x: list[int] = []

Pyright doesn't currently check for this condition.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions