pydanny / cached-property

A decorator for caching properties in classes.
BSD 3-Clause "New" or "Revised" License
688 stars 78 forks source link

Can cached_property be a subclass of property? #26

Open aldanor opened 8 years ago

aldanor commented 8 years ago

There are certain pieces of code in some libraries, linters and static analyzers that check things like

if isinstance(attr, property):
    do_something()

This is especially important for use in metaclasses.

Obviously this fails with cached property; would it be possible to derive it from property so isinstance/issubclass checks work as expected?

pydanny commented 8 years ago

That's a fun idea! There isn't a stupid-quick fix for this: I quickly checked and if we inherit all the cached-property classes from Python's property built-in, then a third of the unit tests fail.

But I'm pretty certain there's a way to do it.

RonnyPfannschmidt commented 8 years ago

since the python property is a data-property, that would mean always having a slow implementation the properties with annotations/ttl however look like a good candidate for that

alimuldal commented 8 years ago

Inheriting from property also seems to fix #27