diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-03-27 08:31:53 -0400 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-03-27 14:40:16 +0200 |
commit | c42fe73a1613bbfb52a5ba9129efa45a3fd76401 (patch) | |
tree | a2a46628b621077b035ce28f038579bfa077d24c | |
parent | dec241b1787e6c99a092bb9ef6a993abf51fea91 (diff) | |
download | pylint-git-c42fe73a1613bbfb52a5ba9129efa45a3fd76401.tar.gz |
Fix false negative for `protected-access` on functions (#5990)
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | pylint/checkers/classes/class_checker.py | 5 | ||||
-rw-r--r-- | tests/functional/p/protected_access.py | 14 | ||||
-rw-r--r-- | tests/functional/p/protected_access.txt | 2 |
4 files changed, 25 insertions, 1 deletions
@@ -29,6 +29,11 @@ Release date: TBA Closes #5803 +* Fix a false negative regression in 2.13.0 where ``protected-access`` was not + raised on functions. + + Fixes #5989 + What's New in Pylint 2.13.1? ============================ diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index e258f6642..f5efc4dc7 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -980,7 +980,7 @@ a metaclass class method.", if attribute.attrname != assign_attr.attrname: continue - if self._is_type_self_call(attribute.expr): + if isinstance(attribute.expr, nodes.Call): continue if assign_attr.expr.name in { @@ -2106,6 +2106,7 @@ a metaclass class method.", """Check if nodes.Name corresponds to first attribute variable name. Name is `self` for method, `cls` for classmethod and `mcs` for metaclass. + Static methods return False. """ if self._first_attrs: first_attr = self._first_attrs[-1] @@ -2116,6 +2117,8 @@ a metaclass class method.", ) if closest_func is None: return False + if not closest_func.is_bound(): + return False if not closest_func.args.args: return False first_attr = closest_func.args.args[0].name diff --git a/tests/functional/p/protected_access.py b/tests/functional/p/protected_access.py index 39769fe76..8d2f945d2 100644 --- a/tests/functional/p/protected_access.py +++ b/tests/functional/p/protected_access.py @@ -27,3 +27,17 @@ class MC: class Application(metaclass=MC): def __no_special__(cls): nargs = obj._nargs # [protected-access] + + +class Light: + @property + def _light_internal(self) -> None: + return None + + @staticmethod + def func(light) -> None: + print(light._light_internal) # [protected-access] + + +def func(light: Light) -> None: + print(light._light_internal) # [protected-access] diff --git a/tests/functional/p/protected_access.txt b/tests/functional/p/protected_access.txt index 570a90638..50e6c5d5b 100644 --- a/tests/functional/p/protected_access.txt +++ b/tests/functional/p/protected_access.txt @@ -1,2 +1,4 @@ protected-access:17:0:17:9::Access to a protected member _teta of a client class:UNDEFINED protected-access:29:16:29:26:Application.__no_special__:Access to a protected member _nargs of a client class:UNDEFINED +protected-access:39:14:39:35:Light.func:Access to a protected member _light_internal of a client class:UNDEFINED +protected-access:43:10:43:31:func:Access to a protected member _light_internal of a client class:UNDEFINED |