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

remove metaclass check for protected access in properties #9966

Merged

Conversation

temyurchenko
Copy link
Contributor

  1. it was incorrect when the property wasn't inside a class and the enclosing class didn't have an explicit metaclass

  2. The conjugated test is full with errors and I can't understand the intention. (the errors: MC doesn't inherit type; _nargs isn't defined; obj isn't defined, etc). What is the pointed of testing protected access on an undefined variable?..

Description

The PR is intentionally extreme (removing the whole test), and I wouldn't be surprised if I missed something and my change is incorrect. I'd be happy to adapt based on the feedback.

The primary reason for this PR is marked as 1. in the commit description (or above).

One situation where this happens is the following. In new astroid "function-call" style properties don't have the enclosing class as the parent. The reason is that the properties themselves are not defined within the class, they are defined within some builtin module. It's just the name that they are assigned to that is defined within the class. So, for example in:

class Foo:
  x = property(lambda self: 5)

x is defined within Foo, but the property itself isn't. You can read more about it here: pylint-dev/astroid#2553

Comment on lines -24 to -26
@property
def nargs(self):
return 1 if self._nargs else 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you just remove the property and see if the tests still passes?

Copy link
Contributor Author

@temyurchenko temyurchenko Sep 25, 2024

Choose a reason for hiding this comment

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

If I comment out @property, it does pass

Copy link

codecov bot commented Sep 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.80%. Comparing base (fa64425) to head (f2591c7).
Report is 7 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #9966      +/-   ##
==========================================
- Coverage   95.80%   95.80%   -0.01%     
==========================================
  Files         174      174              
  Lines       18937    18933       -4     
==========================================
- Hits        18143    18139       -4     
  Misses        794      794              
Files with missing lines Coverage Δ
pylint/checkers/classes/class_checker.py 93.73% <100.00%> (-0.03%) ⬇️

This comment has been minimized.

@temyurchenko
Copy link
Contributor Author

I believe we should «skip news» on this one.

@Pierre-Sassoulas Pierre-Sassoulas added Maintenance Discussion or action around maintaining pylint or the dev workflow Skip news 🔇 This change does not require a changelog entry labels Sep 25, 2024
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Thank you for the PR. Great fan of simplifying the code, not a great fan of removing tests when simplifying the code.

@temyurchenko
Copy link
Contributor Author

Thank you for the PR. Great fan of simplifying the code, not a great fan of removing tests when simplifying the code.

I'd be happy to fix the test instead, but I genuinely don't understand what it's supposed to be doing. It seems to be broken in too many ways to be useful and the intent is unclear as well. I'm not even sure if the behaviour it's testing is correct.

@Pierre-Sassoulas
Copy link
Member

It's been introduced in #2393, there was a crash when an attribute was uninferable, we need to adapt the test to keep checking for that maybe ?

@temyurchenko
Copy link
Contributor Author

temyurchenko commented Oct 11, 2024

It's been introduced in #2393, there was a crash when an attribute was uninferable, we need to adapt the test to keep checking for that maybe ?

I've spent a lot of time trying to find a single path that would lead to an exception described in that issue. I actually kind of began to understand why the test in question is so complicated. Hitting the unhappy path is incredibly involved (and vulnerable to even slight changes in the codebase). So, even when I've removed the fix from that PR, every single test is still passing, including the test in question.

So, I think it really makes sense to remove the test altogether. It was testing the quirks of a database from 6 years ago, and it doesn't apply nowadays.

1. it was incorrect when the property wasn't inside a class and the
   enclosing class didn't have an explicit metaclass

2. The conjugated test is full with errors and I can't understand the
   intention. (the errors: `MC` doesn't inherit `type`; `_nargs` isn't
   defined; `obj` isn't defined, etc). What is the pointed of testing
   protected access on an undefined variable?..
@temyurchenko temyurchenko force-pushed the remove-metaclass-check branch from 4f936d3 to f2591c7 Compare October 11, 2024 17:57
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

@Pierre-Sassoulas Okay to merge this?

Copy link
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit f2591c7

@Pierre-Sassoulas Pierre-Sassoulas merged commit 5feface into pylint-dev:main Oct 17, 2024
44 checks passed
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 pylint or the dev workflow Skip news 🔇 This change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants