summaryrefslogtreecommitdiff
path: root/pylint/checkers/classes.py
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2020-09-26 15:35:54 +0200
committerhippo91 <guillaume.peillex@gmail.com>2020-09-26 15:35:54 +0200
commite78949a74bee6172d3053c01a81c28288aa217b1 (patch)
treeb2178ea6a756378232ec4efea1d07408dd4572fc /pylint/checkers/classes.py
parentc433df74231c8e38d64f3a4e6f0d77b8753eb257 (diff)
downloadpylint-git-e78949a74bee6172d3053c01a81c28288aa217b1.tar.gz
Adds an option to the ClassChecker to activate/deactivate protected-access message emission for single underscore prefixed attributes inside special method
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r--pylint/checkers/classes.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index 890d9f750..90a8fa6f4 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -756,6 +756,15 @@ a metaclass class method.",
),
},
),
+ (
+ "check-protected-access-in-special-methods",
+ {
+ "default": False,
+ "type": "yn",
+ "metavar": "<y or n>",
+ "help": "Warn about protected attribute access inside special methods",
+ },
+ ),
)
def __init__(self, linter=None):
@@ -1418,11 +1427,12 @@ a metaclass class method.",
if _is_attribute_property(name, klass):
return
- # A licit use of protected member is inside a special method
- if not attrname.startswith(
- "__"
- ) and self._is_called_inside_special_method(node):
- return
+ if not self.config.check_protected_access_in_special_methods:
+ # A licit use of protected member is inside a special method
+ if not attrname.startswith(
+ "__"
+ ) and self._is_called_inside_special_method(node):
+ return
self.add_message("protected-access", node=node, args=attrname)