-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix @dataclass
to catch default / non-default fields order
#12159
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
So, here's what happens with overriding from dataclasses import dataclass, field
@dataclass
class Some:
x: int = field(kw_only=True)
@dataclass
class Other(Some):
x: int
print(Other(1)) # Other(x=1) Two fields (there was a difference in the original bug report): from dataclasses import dataclass, field
@dataclass
class Some:
x: int = field(kw_only=True)
@dataclass
class Other(Some):
x: int
y: int
print(Other(1, 2)) Mypy is also happy with this. Funny thingBut, while testing this, I found a different problem: from dataclasses import dataclass, field, KW_ONLY
@dataclass
class Base:
x: int
y: int = field(kw_only=True)
_: KW_ONLY
z: int = 0
@dataclass
class Other(Base): # E: Attributes without a default cannot follow attributes with one
x: int
y: int
z: int I will open a new issue for it and address in a separate PR (if this is a problem at all, some more analysis is needed). |
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This is a new regression: #12173 |
b: int = 2 | ||
|
||
@dataclass | ||
class Wrong1(A): # E: Attributes without a default cannot follow attributes with one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly the runtime accepts this one. It's pretty weird, though, and I'm OK with mypy giving an error for it.
This still has a couple of regressions 😢 |
Closes #12137