Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cached_property decorator doesn't work with mangled method names #102

Open
graingert opened this issue Jun 7, 2018 · 2 comments
Open

cached_property decorator doesn't work with mangled method names #102

graingert opened this issue Jun 7, 2018 · 2 comments

Comments

@graingert
Copy link

graingert commented Jun 7, 2018

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
"""
@graingert
Copy link
Author

Here's a django PR that fixes it: django/django#10033

@pydanny
Copy link
Owner

pydanny commented Sep 30, 2018

@graingert, would you or anyone else like to open a pull request to support this here?

AWhetter added a commit to AWhetter/cached-property that referenced this issue Jul 2, 2019
AWhetter added a commit to AWhetter/cached-property that referenced this issue Jul 2, 2019
AWhetter added a commit to AWhetter/cached-property that referenced this issue Jul 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants