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

x = cached_property(y) doesn't work properly #123

Open
VadimPushtaev opened this issue Oct 10, 2018 · 3 comments
Open

x = cached_property(y) doesn't work properly #123

VadimPushtaev opened this issue Oct 10, 2018 · 3 comments

Comments

@VadimPushtaev
Copy link

from cached_property import cached_property


class A:
    def __init__(self, x):
        self._x = x

    def get_x_len(self):
        print('...')
        return len(self._x)

    x_len = cached_property(get_x_len)


a = A([1, 2, 3])
print(a.get_x_len())
print(a.x_len)
print(a.get_x_len())

This examples fails with TypeError: 'int' object is not callable. The problem is, cached_property replaces get_x_len with 3 while it actually semantically should replacing x_len with 3.

@roelzkie15
Copy link

I did a dirty workaround seems like it works if you do this:

x_len = cached_property(get_x_len).func

@VadimPushtaev
Copy link
Author

I did a dirty workaround seems like it works if you do this:

x_len = cached_property(get_x_len).func

x_len should be a property, not a method.

@roelzkie15
Copy link

I did a dirty workaround seems like it works if you do this:

x_len = cached_property(get_x_len).func

x_len should be a property, not a method.

Hmmm i think you are right, the cached_property(get_x_len).func returned 3 instead of a property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants