Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pylint W0212 protected-access

In Python, prefixing with one underscore indicates that a member should not be accessed outside of its class. This seems to be on a per-class basis like Java and C++.

However, pylint seems to enforce this convention on a per-object basis. Is there a way to allow per-class access without resorting to #pylint: disable=protected-access?

class A:     def __init__(self):         self._b = 5      def __eq__(self, other):         return self._b == other._b 

Result:

pylint a.py a.py:6: W0212(protected-access) Access to a protected member _b of a client class 

Pylint describes the message here.

like image 1000
Jim K Avatar asked Feb 29 '16 14:02

Jim K


1 Answers

pylint doesn't know of which type other is (how should it, you can compare an instance of A to everything), therefore the warning. I don't think there is a way around disabling the warning.

You can disable the warning for only that one line with appending # pylint: disable=W0212 to that line.

like image 185
Christian Geier Avatar answered Sep 22 '22 16:09

Christian Geier