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
dataclasses: make field() with no annotation an error #76686
Comments
This is an attractive nuisance, especially when coming from attrs. Make it an error, since it's using field() with no annotation: @dataclass
class C:
x = field() |
I'm not sure this is worth preventing. I can certainly make it an error, but since dataclasses ignores anything without a type annotation, I don't think it's a big deal. Basically I'd have to look through all class attributes that are of type Field but aren't in the class's __annotations__. I cannot find the original conversation that caused me to open this issue. If anyone feels strongly that this case should be an error, let me know. |
Fine to close as wontfix. |
Some part of the discussion is in https://bugs.python.org/issue32428 I still think it is important to flag things like this as an error: @dataclass
class C:
x = field() This is a big bug magnet. Especially taking into account that attrs behave in the opposite way in this case. |
But surely when you instantiate this: you'll notice that's an error? |
Yes, but there are other scenarios, like using What would we lose by not flagging this as an error? I think there are no legitimate use cases for such code, and implementation is straightforward. If you don't have time I can do this myself. |
Thanks for the offer. I've already got the code written, I just need to write some tests. I'll get it done real soon now. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: