-
Notifications
You must be signed in to change notification settings - Fork 1.8k
dataclasses.replace does not type correctly #1047
Copy link
Copy link
Closed
Labels
enhancement requestNew feature or requestNew feature or request
Description
Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues.
Describe the bug
Hi, I'm using dataclasses with frozen=True as immutable values.
However the very useful 'replace' function from the same module doesn't type correctly (see docs ).
This allows to create a new value by changing fields specified via keyword args.
To Reproduce
Create a dataclass, use the replace function with incorrect arguments.
Expected behavior
Typecheck fail.
Screenshots or Code
from dataclasses import dataclass,replace
@dataclass
class A:
x : int
y : int
a = A(0,1)
b = replace(a,x=1) #types correctly
c = replace(a,not_a_field=1) #should not typecheckVS Code extension or command-line
VS Code extension.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancement requestNew feature or requestNew feature or request