Pylint W0212 protected-access

7 浏览
0 Comments

Pylint W0212 protected-access

在Python中,前缀为一个下划线表示一个成员不应该在其类的外部被访问。这似乎是基于每个类的,类似于Java和C++。

然而,pylint似乎在每个对象上强制执行这个约定。有没有一种方法可以允许每个类的访问,而不必使用#pylint: disable=protected-access?

class A:

def __init__(self):

self._b = 5

def __eq__(self, other):

return self._b == other._b

结果:

pylint a.py

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

pylint在这里描述了消息。

0