Message404648
I can confirm that Juan Arrivillaga (juanpa.arrivillaga) workaround does work.
Given that it works, then wouldn't it be relatively trivial to do what Thomas701 suggests and add a descriptor parameter to fields. Then apply the descriptor after all the other work is done so that it doesn't get clobbered, which is basically reproducing the workaround.
import dataclasses
@dataclasses.dataclass
class FileObject:
_uploaded_by: str = dataclasses.field(default=None, init=False)
def _uploaded_by_getter(self):
return self._uploaded_by
def _uploaded_by_setter(self, uploaded_by):
print('Setter Called with Value ', uploaded_by)
self._uploaded_by = uploaded_by
uploaded_by: str = field(default=None, descriptor=property(
FileObject._uploaded_by_getter,
FileObject._uploaded_by_setter))
p = FileObject()
print(p)
print(p.uploaded_by)
This would allow any descriptor to be applied to a dataclass field. If we allow descriptor to accept an iterable as well you could have multiple descriptors just like normal. |
|
Date |
User |
Action |
Args |
2021-10-21 20:25:23 | Michael Robellard | set | recipients:
+ Michael Robellard, eric.smith, juanpa.arrivillaga, iivanyuk, UnHumbleBen, Thomas701 |
2021-10-21 20:25:23 | Michael Robellard | set | messageid: <1634847923.45.0.959507563393.issue39247@roundup.psfhosted.org> |
2021-10-21 20:25:23 | Michael Robellard | link | issue39247 messages |
2021-10-21 20:25:23 | Michael Robellard | create | |
|