> I agree with Andrew: it's a great idea, but I couldn't come up with a
> way to implement it, so I followed attrs lead instead. Maybe someone can
> come up with a good way to implement it


It seems like this could be solved if a general way could be created to
allow dataclasses to handle descriptors properly? Or if not descriptors
proper, at least a dataclass version of @property?

I'm sure this has been discussed before. But one idea would be to add an
optional "property" argument to `field`, which would turn it into a
descriptor.

So the code could be something like this, maybe:

@dataclasses.dataclass(frozen=True)
class Person:
    name: str
    surname: str
    fullname: str = dataclasses.field(property=True)  # fullname is now a
field descriptor

    @fullname.getter
    def fullname_getter(self):
        return self._fullname

    @fullname.setter
    def fullname_setter(self, value):
        assert value == ????
        self.fullname = f"{self.name} {self.surname}"

If this is a good idea, one big question is what the default __init__
method should supply to the "value" argument.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4P2FBZTTNPJXUMZXYG2KMFQQIHSZGT62/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to