#29478 closed Bug (fixed)
cached_property decorator doesn't work with mangled method names
Reported by: | Thomas Grainger | Owned by: | nobody |
---|---|---|---|
Component: | Utilities | Version: | 2.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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)
comment:1 by , 7 years ago
Component: | Uncategorized → Utilities |
---|---|
Has patch: | set |
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 6 years ago
Had a look at this, and the Foo instance dict does contain the foo (and the foo2, but not the foo3 as expected).
I think this is more a python thing where the double underscore is special and that is the reason it doesn't work and that it has nothing to do with the @cached_property decorator.
Version 0, edited 6 years ago by (next)
comment:3 by , 6 years ago
Patch needs improvement: | unset |
---|
comment:6 by , 6 years ago
Patch needs improvement: | set |
---|
comment:7 by , 6 years ago
Patch needs improvement: | unset |
---|
Note:
See TracTickets
for help on using tickets.
PR