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

Replace cachedproperty with functools.cached_property (>= 3.8) #1410

Closed
cdce8p opened this issue Feb 27, 2022 · 2 comments · Fixed by #1417
Closed

Replace cachedproperty with functools.cached_property (>= 3.8) #1410

cdce8p opened this issue Feb 27, 2022 · 2 comments · Fixed by #1417
Assignees
Labels
Maintenance Discussion or action around maintaining astroid or the dev workflow
Milestone

Comments

@cdce8p
Copy link
Member

cdce8p commented Feb 27, 2022

I thought about this PR recently again. Typing cachedproperty might not work, but it can be replaced with functools.cached_property. We only need to sys guard it for < 3.8. This should work

if sys.version_info >= (3, 8):
    from functools import cached_property
else:
    from astroid.decorators import cachedproperty as cached_property

Additionally, the deprecation warning can be limited to >= 3.8.

Originally posted by @cdce8p in #1243 (comment)

@cdce8p cdce8p added the Maintenance Discussion or action around maintaining astroid or the dev workflow label Feb 27, 2022
@cdce8p cdce8p added this to the 2.11.0 milestone Feb 27, 2022
@DanielNoord
Copy link
Collaborator

@cdce8p Just thinking out loud: can we also use a type guard to define cached_property? Would mypy pick up on that?

@cdce8p
Copy link
Member Author

cdce8p commented Feb 27, 2022

@cdce8p Just thinking out loud: can we also use a type guard to define cached_property? Would mypy pick up on that?

Not completely sure what you want to do with that.

On other thing, I just saw that we don't set the python-version for mypy. If we do that, we probably need to do some more workarounds to tell mypy cachedproperty is equal to cached_property. Adding TYPE_CHECKING could work

if sys.version_info >= (3, 8) or TYPE_CHECKING:
    from functools import cached_property
else:
    from astroid.decorators import cachedproperty as cached_property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Discussion or action around maintaining astroid or the dev workflow
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants