Skip to content

Typecheck dataclasses.replace semantically #5397

@thejcannon

Description

@thejcannon

Is your feature request related to a problem? Please describe.

import dataclasses

@dataclasses.dataclass
class Bar:
    x: int = dataclasses.field()

bar = Bar(1)
dataclasses.replace(bar, x='')  # maybe should error?

Describe the solution you'd like
Ideally, a type error on the last line 😄

I understand it'd require special-casing dataclasses.replace, but I think the pros outweigh the cons.
(maybe https://discuss.python.org/t/generalize-replace-function/28511/14 would also help here?)

Additional context
I was testing if the provisional PEP 712 support did the right thing and found this. When/if this is fixed, mind checking on PEP 712 support? 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions