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 Thomas701
Recipients Michael Robellard, Thomas701, UnHumbleBen, eric.smith, iivanyuk, juanpa.arrivillaga
Date 2021-10-21.22:51:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634856664.31.0.473706299735.issue39247@roundup.psfhosted.org>
In-reply-to
Content
> An example of multiple descriptors would be to have:
> @cached_property
> @property
> def expensive_calc(self):
>     #Do something expensive

That's decorator chaining. The example you gave is not working code (try to return something from expensive_calc and print(obj.expensive_calc()), you'll get a TypeError). Correct me if I'm wrong, but I don't think you can chain descriptors the way you want unless the descriptors themselves have knowledge that they're acting on descriptors. E.g., given:

class Foo:
    @descriptorA
    @descriptorB
    def bar(self):
        return 5

You would need descriptorA to be implemented such that its __get__ method return .__get__() of whatever it was wrapping (in this case descriptorB).

Either way, at the class level (I mean the Foo class, the one we'd like to make a dataclass), all of this doesn't matter because it only sees the outer descriptor (descriptorA). Assuming the proposed solution is accepted, you would be able to do this:

@dataclass
class Foo:
    @descriptorA
    @descriptorB
    def bar(self):
        return some_value
    
    @bar.setter
    def bar(self, value):
        ...  # store value
    
    bar: int = field(descriptor=bar)

and, assuming descriptorA is compatible with descriptorB on both .__get__ and .__set__, as stated above, it would work the way you intend it to.
History
Date User Action Args
2021-10-21 22:51:04Thomas701setrecipients: + Thomas701, eric.smith, Michael Robellard, juanpa.arrivillaga, iivanyuk, UnHumbleBen
2021-10-21 22:51:04Thomas701setmessageid: <1634856664.31.0.473706299735.issue39247@roundup.psfhosted.org>
2021-10-21 22:51:04Thomas701linkissue39247 messages
2021-10-21 22:51:04Thomas701create