-
Notifications
You must be signed in to change notification settings - Fork 12
An error is raised when dealing with dataclasses #30
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
Comments
Seems like the issue comes directly from Python 3.7.4 (default, Aug 6 2019, 15:53:23)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dataclasses import dataclass
>>> @dataclass(init=False)
... class Product:
... name: str
... price: float
...
>>> p = Product()
>>> p
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dataclasses.py", line 357, in wrapper
result = user_function(self)
File "<string>", line 2, in __repr__
AttributeError: 'Product' object has no attribute 'name' I get the impression that dataclasses are not really meant to be completely functional without an from dataclasses import dataclass, field
@dataclass
class Product:
name: str = field(default_factory=list)
price: float = field(default_factory=list) Do you think we should catch the |
Agreed @elacuesta |
Also related: scrapy/scrapy#4642 |
|
@Gallaecio Should that last comment go in |
Indeed 🤦 |
Should we just re-raise as a |
This would require users to set all fields as optional (so they don't get the error). I guess a proper solution might require us to change the API a bit and not expose the item until it is created ( Maybe, the item we expose is a plain |
Note that |
I think there may be some issue in
repr
or similar that raises an exception if thedataclass
is empty (no values set).Here is a minimal example..
The text was updated successfully, but these errors were encountered: