W0212 protected-access

Message

'Access to a protected member %s of a client class'

Description

Used when a protected member (i.e. class member with a name beginning with an underscore) is access outside the class or a descendant of the class where it’s defined.

In Python, every attribute that starts with an underscore is seen as “private”. When Pylint sees an access to such an attribute, it emits a warning. For more information on the topic of private variables and attributes please refer to the related section in Python documentation.

Examples

class A:
    def _private_method(self):
        pass

def main():
    a = A()
    a._private_method()
7:4: W0212: Access to a protected member _private_method of a client class

Why bother?

If something is marked as “private”, the maintainer of that part of the code usually assumes that they can change it without prior warning (and without research if it is used (in a certain way) in other parts of the project). Thus, when we use private interfaces we make our code less robust to changes of those parts.

Running Pylint locally? In your CI?

There is a better way! Run PyCodeQual & get Pylint findings with history, diffs and statistics.

Click here to find out more.