Skip to content

(🎁) Validate arguments to dataclasses utility functions replace and fields #14215

Closed
@KotlinIsland

Description

@KotlinIsland

Mypy should special case these functions to only work with dataclasses.

from dataclasses import dataclass, replace

@dataclass
class D:
    pass
class C:
    pass

replace(D())
replace(C())  # TypeError: replace() should be called on dataclass instances

playground

PS: PyCharm correctly reports these

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions