-
-
Notifications
You must be signed in to change notification settings - Fork 290
Include subclasses of standard property classes as property decorators #2735
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind adding a test for this? There should be other tests for property
that we can adapt :)
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## main #2735 +/- ##
==========================================
+ Coverage 93.21% 93.30% +0.08%
==========================================
Files 93 93
Lines 11072 11080 +8
==========================================
+ Hits 10321 10338 +17
+ Misses 751 742 -9
Flags with carried forward coverage won't be shown. Click here to find out more.
π New features to boost your workflow:
|
Actually, I have hit a problem with this PR as written. It works if my class inherits from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great so far, thank you for digging into this !
I have a possible fix to the subscripting issue. I have started working on the tests. |
Ok, I've updated my original fix so that it handles subclasses of |
I ran the full test suite locally without my PR, and got:
And with my PR, including the 1 additional test (
So at least based on my local pytest execution, the PR does not appear to cause any regressions. |
I see the tests don't cover a few of the non-property cases in the code. I think I know which ones I can add to address this. Hold, please. |
In working on filling out the code coverage, I ran into a question about how we want Some context -- from looking at the I am assuming that this is the desired philosophy into which my PR should fit. But I realized that my PR is making import functools
class cached_property:
pass
class user_property(cached_property):
pass
class user_property_from_functools(functools.cached_property):
pass
class A:
@cached_property
def cached_property(self): return 42
@user_property
def user_property(self): return 42
@user_property_from_functools
def user_property_from_functools(self): return 42 Without my PR in place, then only If we want to retain this idea that cached_property = { int: float }
class user_property(cached_property[int]):
pass Do we want I'm going to modify my PR to allow all 3 cases of my first example, but I will retain the fact that it balks at that last example. Let me know if you disagree with any of that, or if I'm not being clear about it. |
Thinking about it more, it's not quite so simple. My above discussion centered around For the non-subscripted case, this is handled by calling For the subscripted case, I'm already adding code to look at what is being subscripted, and what its base class is. The problem here is that several of the official property types ( I'm actually now thinking that when looking at user classes, we should really just look to see if they inherit from one of the provided property classes. If not, and if the user wants pylint to handle them, then they can add them to the |
Ok, I've added tests to cover all of the situations I described in my earlier comments. I also added tests for other things that had been missing, like for the |
I see that the 3.10 tests are failing with the new |
This PR seems to be the one which claimed |
β¦ty was added in Python 3.11, not 3.10
I've added a commit to change the tests and Oh, I guess I don't have authority to add reviewers. Well, @nelfin if you happen to see this, please give your input. |
LGTM. For context, 3.10 wasn't released in Jul of 2021, that change was for
the alpha release. enum.property was removed in
python/cpython#27010 commit b58dc58
β¦On Thu., 15 May 2025, 8:40 am Mitch Harding, ***@***.***> wrote:
*mharding-hpe* left a comment (pylint-dev/astroid#2735)
<#2735 (comment)>
I've added a commit to change the tests and bases.py to reflect that
enum.property was added in Python 3.11, not 3.10. I'll also add the
original PR author as a reviewer in case there is something going on here
that is not apparent to me.
Oh, I guess I don't have authority to add reviewers. Well, @nelfin
<https://github.com/nelfin> if you happen to see this, please give your
input.
β
Reply to this email directly, view it on GitHub
<#2735 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABSH3KPGEDQX7VMZPMAW6L26OS2XAVCNFSM6AAAAAB46YWS32VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQOBRGUYDCOBYGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Aha -- that makes sense. I should have paid closer attention to the date of the original commit. Thank you for the insight!
|
Working on this PR gave me the thought that there may be other cases that are currently overlooked in the tests (like I saw here for tests validating the other standard property classes). @DanielNoord @Pierre-Sassoulas are you open to further PRs that are purely test improvements/additions, if I see anything worth doing? |
We're open to any PR making the code base better :) your work and in depth digging into issues is appreciated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks awesome!
@Pierre-Sassoulas Do you want to review as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great !
# enum.property was added in Python 3.11 | ||
if PY311_PLUS: | ||
PROPERTIES.add("enum.property") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be based on pylint's py-version
instead ? Not sure if we have the ability to propagate this option to astroid yet. If not I don't know what exactly the design should be. (this is more a question for @DanielNoord)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really have an option to...
Since we haven't had anybody complain about this for 2-3 years after making the mistake I wouldn't bother with adding complicated support for it.
Co-authored-by: Pierre Sassoulas <[email protected]>
Type of Changes
Description
This is my attempt to get
astroid
to automatically recognize subclasses offunctools.cached_property
asproperty
decorators. In my local testing, this change corrects the problem I reported in issue 10377, but I am not at all familiar with the overall codebase here, so I am not confident that this is the appropriate change to make.I also wasn't sure if I should describe this as a bug fix or a new feature. :)
Refs #2306
Closes #10377