Skip to content

mypy should reject non-existent fields with dataclasses.replace #14793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OlegAlexander opened this issue Feb 26, 2023 · 1 comment
Closed

mypy should reject non-existent fields with dataclasses.replace #14793

OlegAlexander opened this issue Feb 26, 2023 · 1 comment

Comments

@OlegAlexander
Copy link

This issue was originally reported by @LunarLanding here:

microsoft/pyright#1047

I believe mypy should reject non-existent fields when dataclasses.replace is used.

To Reproduce

from dataclasses import dataclass, replace

@dataclass(frozen=True) 
class A:
    x : int
    y : int
    
a = A(0, 1)
b = replace(a, x=1) # ok
c = replace(a, not_a_field=1) # should be: error: "A" has no attribute "not_a_field"  [attr-defined]

Mypy Playground

Expected Behavior

Error: "A" has no attribute "not_a_field" [attr-defined]

Actual Behavior

No error

Related Issue

#14525

@OlegAlexander OlegAlexander added the bug mypy got something wrong label Feb 26, 2023
@AlexWaygood AlexWaygood added feature topic-dataclasses and removed bug mypy got something wrong labels Feb 26, 2023
@AlexWaygood
Copy link
Member

Duplicate of #5152

@AlexWaygood AlexWaygood marked this as a duplicate of #5152 Feb 26, 2023
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants