Access to a protected member _bot of a client class
141 # skipcq: PYL-W0212
142 # pylint: disable=protected-access
143 if self.allow_via_bot and self._client._bot is not None:
144 self._client._bot.remove_handler(self._handler, self._group)145
146 self._loaded = False
147 return self.name
Access to a protected member _bot of a client class
127 # skipcq: PYL-W0212
128 # pylint: disable=protected-access
129 if self.allow_via_bot and self._client._bot is not None:
130 self._client._bot.add_handler(self._handler, self._group)131
132 self._loaded = True
133 return self.name
Description
Accessing a protected member (a member prefixed with _
) of a class from outside that class is not recommended, since the creator of that class did not intend this member to be exposed. If accesing this attribute outside of the class is absolutely needed, refactor it such that it becomes part of the public interface of the class.
Bad practice
class Rectangle(object):
def __init__(self, height, width):
self._height = height
self._width = width
r = Rectangle(4, 8)
area = r._height * r._width
Preferred:
class Rectangle(object):
def __init__(self, height, width):
self._height = height
self._width = width
def area():
return self._height * self._width
r = Rectangle(4, 8)
area = r.area()