Uh oh!
There was an error while loading. Please reload this page.
Fix @dataclass to catch default / non-default fields order - #12159
Fix @dataclass to catch default / non-default fields order#12159sobolevn wants to merge 4 commits into
@dataclass to catch default / non-default fields order#12159Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
sobolevn
commented
Feb 13, 2022
So, here's what happens with overriding fromdataclassesimportdataclass, field@dataclassclassSome:
x: int=field(kw_only=True)
@dataclassclassOther(Some):
x: intprint(Other(1)) # Other(x=1)Two fields (there was a difference in the original bug report): fromdataclassesimportdataclass, field@dataclassclassSome:
x: int=field(kw_only=True)
@dataclassclassOther(Some):
x: inty: intprint(Other(1, 2))Mypy is also happy with this. Funny thingBut, while testing this, I found a different problem: fromdataclassesimportdataclass, field, KW_ONLY@dataclassclassBase:
x: inty: int=field(kw_only=True)
_: KW_ONLYz: int=0@dataclassclassOther(Base): # E: Attributes without a default cannot follow attributes with onex: inty: intz: intI 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. 🤖🎉 |
sobolevn
commented
Feb 13, 2022
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.
Interestingly the runtime accepts this one. It's pretty weird, though, and I'm OK with mypy giving an error for it.
sobolevn
commented
Feb 15, 2022
This still has a couple of regressions 😢 |
Closes#12137