Thomas <[email protected]> added the comment:
> 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.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue39247>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com