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

False positive unused-private-member if class member is mutated via cls #4657

Closed
gcolombeau opened this issue Jul 2, 2021 · 3 comments · Fixed by #4663
Closed

False positive unused-private-member if class member is mutated via cls #4657

gcolombeau opened this issue Jul 2, 2021 · 3 comments · Fixed by #4663
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@gcolombeau
Copy link

Steps to reproduce

Given a file w0238.py:

"""unused-private-member (W0238)"""

class UnusedPrivateMember:
    """unused-private-member (W0238)"""

    __attr_a = None
    __attr_b = 'b'

    @classmethod
    def load_attrs(cls):
        """Load attributes."""
        cls.__attr_a = 'a'

    @property
    def attr_a(self):
        """Get a."""
        return self.__attr_a

    @property
    def attr_b(self):
        """Get b."""
        return self.__attr_b

Current behavior

Result of pylint w0238.py:

************* Module w0238
w0238.py:12:8: W0238: Unused private member `UnusedPrivateMember.__attr_a` (unused-private-member)

Expected behavior

I would expect no unused-private-member warning as cls is inferred as the current class.
However, this example feels error prone under edge cases.

pylint --version output

Result of pylint --version output:

pylint 2.9.3
astroid 2.6.2
Python 3.8.3 (default, Jul  3 2020, 09:39:00) 
[GCC 7.5.0]
@yushao2 yushao2 added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jul 3, 2021
@yushao2
Copy link
Collaborator

yushao2 commented Jul 3, 2021

seems similar to #4644 , thanks for reporting this!

@Pierre-Sassoulas
Copy link
Member

Do you want to handle this one @yushao2 ?

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.4 milestone Jul 3, 2021
@alt-yushao2
Copy link

Do you want to handle this one @yushao2 ?

Yep, will work on it later

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 a pull request may close this issue.

4 participants