Search code examples
pythonpylint

How to fix pylint's unused-private-member when assigning to class variables?


I have a class Cursor with some class methods and a class variable __ON:

class Cursor:

    __ON = False

    @classmethod
    def activate(cls) -> None:
        Cursor.__ON = True  # pylint warning here

    @classmethod
    def deactivate(cls) -> None:
        Cursor.__ON = False  # pylint warning here

    @classmethod
    def activated(cls) -> bool:
        return Cursor.__ON

After a recent upgrade of pylint:

$ pylint --version
pylint 2.9.6
astroid 2.6.5
Python 3.9.6 (default, Jul 16 2021, 00:00:00) 
[GCC 11.1.1 20210531 (Red Hat 11.1.1-3)]

I now get these two warnings (which I did not have with previous versions):

test.py:7:8: W0238: Unused private member `Cursor.__ON` (unused-private-member)
test.py:11:8: W0238: Unused private member `Cursor.__ON` (unused-private-member)

I have seen similar bugs:

But these two are fixed in pylint 2.9.6.

Is this another pylint issue or I am missing something?


Solution

  • This is a false positive in pylint, it will be fixed by this merge request and released in pylint 2.10.0.