This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Michael Robellard
Recipients Michael Robellard, Thomas701, UnHumbleBen, eric.smith, iivanyuk, juanpa.arrivillaga
Date 2021-10-21.20:25:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634847923.45.0.959507563393.issue39247@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-10-21 20:25:23Michael Robellardsetrecipients: + Michael Robellard, eric.smith, juanpa.arrivillaga, iivanyuk, UnHumbleBen, Thomas701
2021-10-21 20:25:23Michael Robellardsetmessageid: <1634847923.45.0.959507563393.issue39247@roundup.psfhosted.org>
2021-10-21 20:25:23Michael Robellardlinkissue39247 messages
2021-10-21 20:25:23Michael Robellardcreate