STINNER Victor <vstin...@redhat.com> added the comment:
Exmaple 1: --- import abc import functools class AbstractExpensiveCalculator(abc.ABC): @abc.abstractmethod @functools.cached_property def calculate(self): pass AbstractExpensiveCalculator() --- Exmaple 2: --- import abc import functools class AbstractExpensiveCalculator(abc.ABC): @functools.cached_property @abc.abstractmethod def calculate(self): pass AbstractExpensiveCalculator() --- Current behavior: Example 1 raises an exception as expected, Example 2 instanciate the object: no exception is raised. PR 9904 looks like a reasonable change to me. > The cached_property decorator is not inherited by overriding properties. I > don't think that combining the cached_property and the @abstractmethod > decorators should be supported. Well, maybe we can hack something to make Example 2 fail as well, but I like the idea of using @functools.cached_property in an abstract class as "documentation". To announce that the property will be cached, even if technically it will not be cached. It's more to use the code as documentation than to execute any code. PR 9904 is just 4 lines of code to make the code "works as expected". ---------- nosy: +vstinner _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34995> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com