diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-11-15 10:22:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-15 09:22:19 +0100 |
commit | cff6d39b0ce57299d51f2321c0b6e6e761d9feeb (patch) | |
tree | 59b65d8b4d43671d5758566da9305d861925403f | |
parent | 48d584babd0df99bd469aba0e4aeed3d8f97fff9 (diff) | |
download | pylint-git-cff6d39b0ce57299d51f2321c0b6e6e761d9feeb.tar.gz |
Fix crash for ``protected-access`` on (outer)-class traversal (#5305)
* Fix crash for ``protected-access`` on (outer)-class traversal
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | doc/whatsnew/2.12.rst | 2 | ||||
-rw-r--r-- | pylint/checkers/classes.py | 2 | ||||
-rw-r--r-- | tests/functional/r/regression_02/regression_protected_access.py | 19 | ||||
-rw-r--r-- | tests/functional/r/regression_02/regression_protected_access.txt | 1 |
5 files changed, 25 insertions, 1 deletions
@@ -175,6 +175,8 @@ Release date: TBA Follow-up in #5259 +* Fix crash for ``protected-access`` on (outer) class traversal + * Added new checker ``useless-with-lock`` to find incorrect usage of with statement and threading module locks. Emitted when ``with threading.Lock():`` is used instead of ``with lock_instance:``. diff --git a/doc/whatsnew/2.12.rst b/doc/whatsnew/2.12.rst index b69af3289..97957d7c5 100644 --- a/doc/whatsnew/2.12.rst +++ b/doc/whatsnew/2.12.rst @@ -179,6 +179,8 @@ Other Changes Closes #4580 +* Fix crash for ``protected-access`` on (outer) class traversal + * Make yn validator case insensitive, to allow for ``True`` and ``False`` in config files. * The last version compatible with python '3.6.0' and '3.6.1' is pylint '2.9.3'. We did not diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index cd3e1178c..319a37f73 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -1624,7 +1624,7 @@ a metaclass class method.", parents_callee = callee.split(".") parents_callee.reverse() for callee in parents_callee: - if callee != outer_klass.name: + if not outer_klass or callee != outer_klass.name: inside_klass = False break diff --git a/tests/functional/r/regression_02/regression_protected_access.py b/tests/functional/r/regression_02/regression_protected_access.py new file mode 100644 index 000000000..df36f6795 --- /dev/null +++ b/tests/functional/r/regression_02/regression_protected_access.py @@ -0,0 +1,19 @@ +"""Test for the regression on (outer)-class traversal for private methods +MyClass does not have an outerclass which previously crashed the protected-access check +""" +# pylint: disable=too-few-public-methods + + +class MyClass: + """Test class""" + + @staticmethod + def _a_private_method(): + """Private method that references the class itself""" + return MySecondClass.MyClass._a_private_method() # [protected-access] + + +class MySecondClass: + """Class that uses MyClass""" + + MyClass = MyClass diff --git a/tests/functional/r/regression_02/regression_protected_access.txt b/tests/functional/r/regression_02/regression_protected_access.txt new file mode 100644 index 000000000..e3577b4b1 --- /dev/null +++ b/tests/functional/r/regression_02/regression_protected_access.txt @@ -0,0 +1 @@ +protected-access:13:15:MyClass._a_private_method:Access to a protected member _a_private_method of a client class:HIGH |