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

Allow protected-access in class methods #4267

Merged

Conversation

irgeek
Copy link
Contributor

@irgeek irgeek commented Mar 30, 2021

Steps

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

This is a pretty basic change to allow accessing protected member inside class methods. It performs three checks:

  1. Are we in a class method
  2. Is the inferred value of the access expression an instance of the class
  3. Is the attribute name being accessed an instance or class member of the class

If all three check out, then we allow access to protected members.

I've added tests for the new behaviour, as well as some (potentially redundant) tests to make sure I wasn't picking up attributes of other classes.

I wasn't 100% sure about how to structure the change log entries, but I've added what I thought was correct. If they need to be amended I can certainly do that.

Type of Changes

Type
✨ New feature

Related Issue

Closes #1159

@coveralls
Copy link

coveralls commented Mar 30, 2021

Coverage Status

Coverage increased (+0.007%) to 91.463% when pulling c4c1087 on irgeek:classmethod-protected-access into 8cab76f on PyCQA:master.

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.

Very nice fix, with a lot of test case :) !

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code labels Apr 1, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.7.5 milestone Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

protected-access and @classmethod cls
3 participants