
What about 'staticproperties'? On 20.08.2015 18:07, Erik Bray wrote:
On Thu, Aug 20, 2015 at 11:57 AM, Sven R. Kunze <srkunze@mail.de> wrote:
On 20.08.2015 17:31, Thomas Güttler wrote:
The following solution provides an @classproperty: http://stackoverflow.com/a/5191224/633961
I have not tried setting the value yet, but getting the value works very fine.
It would be great to have "@classproperty" even in Python2. Or at least installable via pip.
I am just a user in this case. I don't know about the best, cleanest, most efficient way to implement this.
Reminds me of cached_property: https://pypi.python.org/pypi/cached-property/0.1.5
I feel it could be useful to have a holistic solution (property + cached + instance,classes,modules) in the stdlib/Python somehow. Having something like a cached-property (or the lazy=True option in my classproperty implementation) is rather nice, but as Guido points out it's out of scope for a general implementation of @classproperty (it's also easy enough to implement memoization patterns outside the stdlib).
However, for (settable) @classproperty to work seamlessly, without having to involve custom metaclasses, would require a CPython implementation and probably a PEP. For in order for this to work it would have to be special-cased, since assignments to a class attribute don't normally go through <descriptor>.__set__.
Erik