diff options
author | tiagohonorato <61059243+tiagohonorato@users.noreply.github.com> | 2021-03-21 16:29:31 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-21 20:29:31 +0100 |
commit | 394060e563a020f33bc29f09461c7e38ca3ff50c (patch) | |
tree | 06e57bd974434e70ce5ca193a9ffc4c41410b603 /pylint/checkers/classes.py | |
parent | 02a3a924420652835a4dbb3ccbede410aae9084b (diff) | |
download | pylint-git-394060e563a020f33bc29f09461c7e38ca3ff50c.tar.gz |
Fix private method hidden by ancestor class attribute (#4177)
* Fix private method hidden by ancestor class attribute
A class defined private method won't be hidden by an ancestor class private
attribute as the class will mangle the latter to avoid naming collisions.
Add tests to assert method-hidden : Although private attributes from the
parent class should not hide methods in the child class, this is not true for
protected attributes. This test ensures that ``method-hidden`` catches the
error when private attributes are not in use.
Signed-off-by: Tiago Honorato <tiagohonorato1@gmail.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r-- | pylint/checkers/classes.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index d475cfcfb..c96cce007 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -1000,6 +1000,8 @@ a metaclass class method.", # If a subclass defined the method then it's not our fault. for ancestor in klass.ancestors(): + if node.name in ancestor.instance_attrs and is_attr_private(node.name): + return for obj in ancestor.lookup(node.name)[1]: if isinstance(obj, astroid.FunctionDef): return |