Message359528
I ran into a strange issue while trying to use a dataclass together with a property.
I have it down to a minumum to reproduce it:
import dataclasses
@dataclasses.dataclass
class FileObject:
_uploaded_by: str = dataclasses.field(default=None, init=False)
uploaded_by: str = None
def save(self):
print(self.uploaded_by)
@property
def uploaded_by(self):
return self._uploaded_by
@uploaded_by.setter
def uploaded_by(self, uploaded_by):
print('Setter Called with Value ', uploaded_by)
self._uploaded_by = uploaded_by
p = FileObject()
p.save()
This outputs:
Setter Called with Value <property object at 0x7faeb00150b0>
<property object at 0x7faeb00150b0>
I would expect to get None instead
Here is the StackOverflow Question where I started this:
https://stackoverflow.com/questions/59623952/weird-issue-when-using-dataclass-and-property-together |
|
Date |
User |
Action |
Args |
2020-01-07 17:35:37 | Michael Robellard | set | recipients:
+ Michael Robellard |
2020-01-07 17:35:37 | Michael Robellard | set | messageid: <1578418537.56.0.0565923550129.issue39247@roundup.psfhosted.org> |
2020-01-07 17:35:37 | Michael Robellard | link | issue39247 messages |
2020-01-07 17:35:36 | Michael Robellard | create | |
|