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

Implemented unused-private-member checker #4504

Merged
merged 4 commits into from
May 25, 2021

Conversation

yushao2
Copy link
Collaborator

@yushao2 yushao2 commented May 25, 2021

Steps

  • 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

Implemented unused-private-member checker, which is emitted when a private member of a class is defined but unused

Checks for:

  • Private class variables
  • Private instance attributes
  • Private methods

Type of Changes

Type
✨ New feature

Related Issue

Closes #4483

@coveralls
Copy link

coveralls commented May 25, 2021

Coverage Status

Coverage increased (+0.02%) to 91.825% when pulling 92d1d31 on yushao2:checkers-4483 into fc28cec on PyCQA:master.

@yushao2 yushao2 force-pushed the checkers-4483 branch 2 times, most recently from e11c9f1 to 5639244 Compare May 25, 2021 03:37
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 this new checker, it will permit to clean up a lot of unused code in badly tested code bases !

def __my_print(self, string):
print(self.__another_secret + string)
another_obj = AnotherClass()
another_obj.__test() # this class's test should still be unused
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -636,6 +636,11 @@ def _has_same_layout_slots(slots, assigned_value):
"Used when a method parameter has a different name than in "
"the implemented interface or in an overridden method.",
),
"W0238": (
"Unused private member of class %s: %s",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Unused private member of class %s: %s",
"Unused private member '%s.%s'",

@Pierre-Sassoulas Pierre-Sassoulas merged commit 44eab78 into pylint-dev:master May 25, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.8.3 milestone May 25, 2021
@cdce8p
Copy link
Member

cdce8p commented May 25, 2021

I found a false positive. It's not that common for python, but at times used for the singleton pattern.

class MyCls:
    __class_var = None

    @classmethod
    def set_class_var(cls, var):
        cls.__class_var = var  # false-positive: unused-private-member

    @classmethod
    def get_class_var(cls):
        return cls.__class_var

@yushao2
Copy link
Collaborator Author

yushao2 commented May 25, 2021

I found a false positive. It's not that common for python, but at times used for the singleton pattern.

class MyCls:
    __class_var = None

    @classmethod
    def set_class_var(cls, var):
        cls.__class_var = var  # false-positive: unused-private-member

    @classmethod
    def get_class_var(cls):
        return cls.__class_var

I'll look into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add check for unused private members
4 participants