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

[unused-private-member] add logic to check for obj attributes when using __new__ #4708

Merged
merged 2 commits into from Jul 18, 2021

Conversation

yushao2
Copy link
Collaborator

@yushao2 yushao2 commented Jul 13, 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

Fix false positive when using __new__ in a class, this is done by performing the following:

  1. If the current method is __new__, get all returned object names by the method
  2. Check and do not emit when the current expression of the attribute is in this list of object names, and a self.attribute of the same attribute was consumed in other methods of the same class

Type of Changes

Type
🐛 Bug fix

Related Issue

Closes #4668

@yushao2 yushao2 added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jul 13, 2021
@yushao2 yushao2 requested a review from cdce8p July 13, 2021 14:15
@yushao2 yushao2 changed the title [unused-private-member] add logic to check for obj attributes when using new [unused-private-member] add logic to check for obj attributes when using __new__ Jul 13, 2021
@coveralls
Copy link

coveralls commented Jul 13, 2021

Coverage Status

Coverage increased (+0.002%) to 92.058% when pulling 4ddde1e on yushao2:fix-unused-private-member into 7b83d90 on PyCQA:main.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.4 milestone Jul 13, 2021
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.

LGTM, thank you !

pylint/checkers/classes.py Outdated Show resolved Hide resolved
pylint/checkers/classes.py Outdated Show resolved Hide resolved
pylint/checkers/classes.py Outdated Show resolved Hide resolved
ChangeLog Outdated Show resolved Hide resolved
Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

Looks good now!

@yushao2 yushao2 merged commit f6c8138 into pylint-dev:main Jul 18, 2021
@yushao2 yushao2 deleted the fix-unused-private-member branch July 18, 2021 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

False positive unused-private-member when using __new__
4 participants