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 vstinner
Recipients methane, mwilbz, serhiy.storchaka, vstinner
Date 2018-10-25.21:04:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1540501477.47.0.788709270274.issue34995@psf.upfronthosting.co.za>
In-reply-to
Content
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".
History
Date User Action Args
2018-10-25 21:04:37vstinnersetrecipients: + vstinner, methane, serhiy.storchaka, mwilbz
2018-10-25 21:04:37vstinnersetmessageid: <1540501477.47.0.788709270274.issue34995@psf.upfronthosting.co.za>
2018-10-25 21:04:37vstinnerlinkissue34995 messages
2018-10-25 21:04:37vstinnercreate