msg309586 - (view) |
Author: Eric V. Smith (eric.smith) *  |
Date: 2018-01-06 22:21 |
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() |
|
|
msg314226 - (view) |
Author: Eric V. Smith (eric.smith) *  |
Date: 2018-03-21 21:53 |
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. |
|
|
msg314227 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2018-03-21 22:22 |
Fine to close as wontfix. |
|
|
msg314228 - (view) |
Author: Ivan Levkivskyi (levkivskyi) *  |
Date: 2018-03-21 23:43 |
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. |
|
|
msg314231 - (view) |
Author: Eric V. Smith (eric.smith) *  |
Date: 2018-03-22 01:47 |
But surely when you instantiate this: c = C(1) you'll notice that's an error? |
|
|
msg314259 - (view) |
Author: Ivan Levkivskyi (levkivskyi) *  |
Date: 2018-03-22 14:14 |
> you'll notice that's an error? Yes, but there are other scenarios, like using `init=False` or updating existing class definition and forgetting to update call sites (which will still work), etc. 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. |
|
|
msg314263 - (view) |
Author: Eric V. Smith (eric.smith) *  |
Date: 2018-03-22 14:48 |
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. |
|
|
msg314290 - (view) |
Author: Eric V. Smith (eric.smith) *  |
Date: 2018-03-22 20:28 |
New changeset 56970b8ce9d23269d20a76f13c80e670c856ba7f by Eric V. Smith in branch 'master': bpo-32505: dataclasses: raise TypeError if a member variable is of type Field, but doesn't have a type annotation. (GH-6192) https://github.com/python/cpython/commit/56970b8ce9d23269d20a76f13c80e670c856ba7f |
|
|
msg314293 - (view) |
Author: miss-islington (miss-islington) |
Date: 2018-03-22 20:59 |
New changeset 3b4c6b16c597aa2356f5658dd67da7dcd4434038 by Miss Islington (bot) in branch '3.7': bpo-32505: dataclasses: raise TypeError if a member variable is of type Field, but doesn't have a type annotation. (GH-6192) https://github.com/python/cpython/commit/3b4c6b16c597aa2356f5658dd67da7dcd4434038 |
|
|