Skip to content
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

attrs deviation from PEP 681 #1170

Open
alonme opened this issue Aug 1, 2023 · 4 comments
Open

attrs deviation from PEP 681 #1170

alonme opened this issue Aug 1, 2023 · 4 comments
Labels
dataclasses dataclass features we're lacking Typing Typing/stub/Mypy/PyRight related bugs.

Comments

@alonme
Copy link

alonme commented Aug 1, 2023

According to the Pylance developers attrs deviates from PEP 681 in the way it treats kw_only in field override
microsoft/pylance-release#4670

@hynek hynek added the Typing Typing/stub/Mypy/PyRight related bugs. label Nov 17, 2023
@radugrosu
Copy link

probably related: microsoft/pyright#6572

@alonme
Copy link
Author

alonme commented Nov 30, 2023

Hey @hynek,

What are your thoughts around this issue?
Is this breaking change something that you are willing to change in attrs?
Are contributions to solve this issue welcome?

@hynek
Copy link
Member

hynek commented Dec 30, 2023

I don’t think those two issues are related.

The Pyright issue is that dataclasses implement the MRO wrong which becomes obvious with multiple inheritance. To be fair, it might’ve copied it from early attrs versions that did it wrong too. Changing that would be a very hard backwards-compatibility breakage in addition to plainly wrong. It's the default in @attr.s. Generally speaking, design-wise I think the advice to only use kwargs in such hierarchies is probably the best.

My understanding of the kw_only issue seems like dataclasses inherit fields configuration?? Do they do that for all config? There’s a bunch of issues around this topic here that went nowhere so far. I could imagine adding an inherit_fields option to define, but I’m not sure if that would help you since it still requires you to pass additional arguments. Cc @Tinche

I think there even was an issue asking for a dataclass compat API so I guess we could reimplement some their bugs within our @dataclass Easter egg too if there’s enough interest.


I’m sorry by not being responsive here, but I get angry whenever I re-read the pontification of how we implement a PEP wrong which has been written long after attrs was implemented and that was the only way for us to get any Pylance/Pyright support whatsoever. We had no choice in this matter and did our best to cooperate and them pointing fingers at us now for not breaking our users doesn't feel great.

@hynek hynek added the dataclasses dataclass features we're lacking label Mar 14, 2024
@asford
Copy link
Contributor

asford commented Mar 29, 2024

Drive-by cross-referencing...

#565
#686

are prior issues on the "attrs-is-dataclasses-plus" namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dataclasses dataclass features we're lacking Typing Typing/stub/Mypy/PyRight related bugs.
Projects
None yet
Development

No branches or pull requests

4 participants