Message328491
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". |
|
Date |
User |
Action |
Args |
2018-10-25 21:04:37 | vstinner | set | recipients:
+ vstinner, methane, serhiy.storchaka, mwilbz |
2018-10-25 21:04:37 | vstinner | set | messageid: <1540501477.47.0.788709270274.issue34995@psf.upfronthosting.co.za> |
2018-10-25 21:04:37 | vstinner | link | issue34995 messages |
2018-10-25 21:04:37 | vstinner | create | |
|