cached-property
cached-property copied to clipboard
cached_property decorator doesn't work with mangled method names
See also https://code.djangoproject.com/ticket/29478#ticket
import itertools
from cached_property import cached_property
count = itertools.count()
count2 = itertools.count()
count3 = itertools.count()
class Foo:
@cached_property
def __foo(self):
return next(count)
@cached_property
def foo2(self):
return next(count2)
@property
def foo3(self):
return next(count3)
def run(self):
print('foo', self.__foo)
print('foo', self.__foo)
print('foo', self.__foo)
print('foo', self.__foo)
print('foo2', self.foo2)
print('foo2', self.foo2)
print('foo2', self.foo2)
print('foo2', self.foo2)
print('foo2', self.foo2)
print('foo3', self.foo3)
print('foo3', self.foo3)
print('foo3', self.foo3)
print('foo3', self.foo3)
print('foo3', self.foo3)
Foo().run()
"""
python cached_property_test.py
foo 0
foo 1
foo 2
foo 3
foo2 0
foo2 0
foo2 0
foo2 0
foo2 0
foo3 0
foo3 1
foo3 2
foo3 3
foo3 4
"""
Here's a django PR that fixes it: https://github.com/django/django/pull/10033
@graingert, would you or anyone else like to open a pull request to support this here?