diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-10-31 05:55:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-31 05:55:46 +0100 |
commit | db5d77c2849e1ee20adef401d1b56c19e1c0fb55 (patch) | |
tree | 8500b065a94fe7ce92bea4fdcab1db5bc779742e /pylint/checkers/classes.py | |
parent | 1d3a7ff32b0f6d819b17ce18345502fbc47b48c9 (diff) | |
download | pylint-git-db5d77c2849e1ee20adef401d1b56c19e1c0fb55.tar.gz |
Fix ``protected-access`` for attributes and methods of nested classes (#5232)
* Fix access to private function in inner class on protected-access bug
* Add functional test for protected-access from inner class
* Add Ikraduya to CONTRIBUTORS file
* Add if statement to avoid potential bug
* Fix ``protected-access`` for attributes and methods of nested classes
This closes #3066
Co-authored-by: ikraduya <ikraduya@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 | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index f6db8a73f..730f2e659 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -63,6 +63,7 @@ from pylint.checkers.utils import ( class_is_abstract, decorated_with, decorated_with_property, + get_outer_class, has_known_bases, is_attr_private, is_attr_protected, @@ -1606,9 +1607,22 @@ a metaclass class method.", if self._is_type_self_call(node.expr): return + # Check if we are inside the scope of a class or nested inner class + inside_klass = True + outer_klass = klass + parents_callee = callee.split(".") + parents_callee.reverse() + for callee in parents_callee: + if callee != outer_klass.name: + inside_klass = False + break + + # Move up one level within the nested classes + outer_klass = get_outer_class(outer_klass) + # We are in a class, one remaining valid cases, Klass._attr inside # Klass - if not (callee == klass.name or callee in klass.basenames): + if not (inside_klass or callee in klass.basenames): # Detect property assignments in the body of the class. # This is acceptable: # |