Message404700
> 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. |
|
Date |
User |
Action |
Args |
2021-10-21 22:51:04 | Thomas701 | set | recipients:
+ Thomas701, eric.smith, Michael Robellard, juanpa.arrivillaga, iivanyuk, UnHumbleBen |
2021-10-21 22:51:04 | Thomas701 | set | messageid: <1634856664.31.0.473706299735.issue39247@roundup.psfhosted.org> |
2021-10-21 22:51:04 | Thomas701 | link | issue39247 messages |
2021-10-21 22:51:04 | Thomas701 | create | |
|