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
--
Ticket URL: <https://code.djangoproject.com/ticket/29478>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* component: Uncategorized => Utilities
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
[https://github.com/django/django/pull/10033 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:1>
* status: new => assigned
* owner: nobody => hehaha
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:2>
* status: assigned => new
* owner: Xin He => (none)
Comment:
It's seem another pull request to fix the ticket on Github. So I have to
deassign it.
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:3>
Comment (by Harro):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:2>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:3>
Comment (by Tim Graham <timograham@…>):
In [changeset:"09199734d383691ecf6d163894b447ca45e0ef82" 09199734]:
{{{
#!CommitTicketReference repository=""
revision="09199734d383691ecf6d163894b447ca45e0ef82"
Refs #29478 -- Doc'd how to use cached_property with a mangled name.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:4>
Comment (by Tim Graham <timograham@…>):
In [changeset:"2a637a45232fa5f046034958a6df91804bbab32c" 2a637a45]:
{{{
#!CommitTicketReference repository=""
revision="2a637a45232fa5f046034958a6df91804bbab32c"
[2.1.x] Refs #29478 -- Doc'd how to use cached_property with a mangled
name.
Backport of 09199734d383691ecf6d163894b447ca45e0ef82 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:5>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:7>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"80ba7a881f9810404ba8a660548f1757f8243562" 80ba7a8]:
{{{
#!CommitTicketReference repository=""
revision="80ba7a881f9810404ba8a660548f1757f8243562"
Fixed cached_properties that share a common property.
The aliases aren't cached and thus the old usage will be an error after
refs #29478.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:8>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"06076999026091cf007d8ea69146340a361259f8" 06076999]:
{{{
#!CommitTicketReference repository=""
revision="06076999026091cf007d8ea69146340a361259f8"
Fixed #29478 -- Added support for mangled names to cached_property.
Co-Authored-By: Sergey Fedoseev <fedosee...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"3b64e2b77570c73a0d7092124fa73439e0fb4305" 3b64e2b7]:
{{{
#!CommitTicketReference repository=""
revision="3b64e2b77570c73a0d7092124fa73439e0fb4305"
Refs #29478 -- Clarified cached_property 2.2 release note.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:10>
Comment (by Tim Graham <timograham@…>):
In [changeset:"c3655b152868176359206a7a759ac38ea5e9c047" c3655b1]:
{{{
#!CommitTicketReference repository=""
revision="c3655b152868176359206a7a759ac38ea5e9c047"
[2.2.x] Refs #29478 -- Clarified cached_property 2.2 release note.
Backport of 3b64e2b77570c73a0d7092124fa73439e0fb4305 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29478#comment:11>