Skip to content

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented May 4, 2021

Description

Add support for functools.cached_property decorator. https://docs.python.org/3/library/functools.html#functools.cached_property

Closes #8913
Closes python/typeshed#3963

Test Plan

I added a new test case. Additionally, I used this snipped to verify mypy during development of the patch

from functools import cached_property

class Parent:
    @property
    def prop(self) -> int:
        ...

class Child(Parent):
    def __init__(self):
        self._prop = 4

    @cached_property
    def prop(self) -> int:
        print("Calc value ..")
        return self._prop ** 2

c = Child()
print(c.prop)
print(c.prop)  # Returns cached value

c.prop = 24  # Overwrite cached value
print(c.prop)

c.prop = "Hello World"  # incompatiable types
print(c.prop)

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, lgtm!

@cdce8p
Copy link
Collaborator Author

cdce8p commented May 4, 2021

Checks all passed

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

Successfully merging this pull request may close these issues.

support cached_property Make cached_property compatible with property
3 participants