cached_property decorator doesn't work with mangled method names
import itertools
from django.utils.functional 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
"""
Odd it's not been reported before: https://code.djangoproject.com/search?q=cached_property+mangled
Change History
(11)
Component: |
Uncategorized → Utilities
|
Has patch: |
set
|
Patch needs improvement: |
set
|
Triage Stage: |
Unreviewed → Accepted
|
Type: |
Uncategorized → Bug
|
Patch needs improvement: |
unset
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
PR