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 /tests/functional/a | |
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 'tests/functional/a')
-rw-r--r-- | tests/functional/a/access/access_to_protected_members.py | 64 | ||||
-rw-r--r-- | tests/functional/a/access/access_to_protected_members.txt | 42 |
2 files changed, 91 insertions, 15 deletions
diff --git a/tests/functional/a/access/access_to_protected_members.py b/tests/functional/a/access/access_to_protected_members.py index ffbfabf15..7d732dcc5 100644 --- a/tests/functional/a/access/access_to_protected_members.py +++ b/tests/functional/a/access/access_to_protected_members.py @@ -211,3 +211,67 @@ class Issue1159Subclass(Issue1159): instance = Issue1159OtherClass() instance._bar = 3 # [protected-access] _ = instance._foo # [protected-access] + + +class Issue3066: + """Test for GitHub issue 3066 + Accessing of attributes/methods of inner and outer classes + https://github.com/PyCQA/pylint/issues/3066""" + + attr = 0 + _attr = 1 + + @staticmethod + def _bar(i): + """Docstring.""" + + @staticmethod + def foobar(i): + """Test access from outer class""" + Issue3066._attr = 2 + Issue3066.Aclass._attr = "y" # [protected-access] + Issue3066.Aclass.Bclass._attr = "b" # [protected-access] + + Issue3066._bar(i) + Issue3066.Aclass._bar(i) # [protected-access] + Issue3066.Aclass.Bclass._bar(i) # [protected-access] + + class Aclass: + """Inner class for GitHub issue 3066""" + + _attr = "x" + + @staticmethod + def foobar(i): + """Test access from inner class""" + Issue3066._attr = 2 # [protected-access] + Issue3066.Aclass._attr = "y" + Issue3066.Aclass.Bclass._attr = "b" # [protected-access] + + Issue3066._bar(i) # [protected-access] + Issue3066.Aclass._bar(i) + Issue3066.Aclass.Bclass._bar(i) # [protected-access] + + @staticmethod + def _bar(i): + """Docstring.""" + + class Bclass: + """Inner inner class for GitHub issue 3066""" + + _attr = "a" + + @staticmethod + def foobar(i): + """Test access from inner inner class""" + Issue3066._attr = 2 # [protected-access] + Issue3066.Aclass._attr = "y" # [protected-access] + Issue3066.Aclass.Bclass._attr = "b" + + Issue3066._bar(i) # [protected-access] + Issue3066.Aclass._bar(i) # [protected-access] + Issue3066.Aclass.Bclass._bar(i) + + @staticmethod + def _bar(i): + """Docstring.""" diff --git a/tests/functional/a/access/access_to_protected_members.txt b/tests/functional/a/access/access_to_protected_members.txt index 1b93683db..3f127f70c 100644 --- a/tests/functional/a/access/access_to_protected_members.txt +++ b/tests/functional/a/access/access_to_protected_members.txt @@ -1,16 +1,28 @@ -protected-access:19:14:MyClass.test:Access to a protected member _haha of a client class -protected-access:41:0::Access to a protected member _protected of a client class -protected-access:42:6::Access to a protected member _protected of a client class -protected-access:43:0::Access to a protected member _cls_protected of a client class -protected-access:44:6::Access to a protected member _cls_protected of a client class -protected-access:58:19:Issue1031.incorrect_access:Access to a protected member _protected of a client class -protected-access:72:48:Issue1802.__eq__:Access to a protected member __private of a client class -protected-access:80:32:Issue1802.not_in_special:Access to a protected member _foo of a client class -protected-access:100:32:Issue1802.__fake_special__:Access to a protected member _foo of a client class -protected-access:162:8:Issue1159.access_other_attr:Access to a protected member _bar of a client class -protected-access:163:12:Issue1159.access_other_attr:Access to a protected member _foo of a client class +protected-access:19:14:MyClass.test:Access to a protected member _haha of a client class:HIGH +protected-access:41:0::Access to a protected member _protected of a client class:HIGH +protected-access:42:6::Access to a protected member _protected of a client class:HIGH +protected-access:43:0::Access to a protected member _cls_protected of a client class:HIGH +protected-access:44:6::Access to a protected member _cls_protected of a client class:HIGH +protected-access:58:19:Issue1031.incorrect_access:Access to a protected member _protected of a client class:HIGH +protected-access:72:48:Issue1802.__eq__:Access to a protected member __private of a client class:HIGH +protected-access:80:32:Issue1802.not_in_special:Access to a protected member _foo of a client class:HIGH +protected-access:100:32:Issue1802.__fake_special__:Access to a protected member _foo of a client class:HIGH +protected-access:162:8:Issue1159.access_other_attr:Access to a protected member _bar of a client class:HIGH +protected-access:163:12:Issue1159.access_other_attr:Access to a protected member _foo of a client class:HIGH no-member:194:12:Issue1159Subclass.access_missing_member:Instance of 'Issue1159Subclass' has no '_baz' member; maybe '_bar'?:INFERENCE -protected-access:194:12:Issue1159Subclass.access_missing_member:Access to a protected member _baz of a client class -attribute-defined-outside-init:203:8:Issue1159Subclass.assign_missing_member:Attribute '_qux' defined outside __init__ -protected-access:212:8:Issue1159Subclass.access_other_attr:Access to a protected member _bar of a client class -protected-access:213:12:Issue1159Subclass.access_other_attr:Access to a protected member _foo of a client class +protected-access:194:12:Issue1159Subclass.access_missing_member:Access to a protected member _baz of a client class:HIGH +attribute-defined-outside-init:203:8:Issue1159Subclass.assign_missing_member:Attribute '_qux' defined outside __init__:HIGH +protected-access:212:8:Issue1159Subclass.access_other_attr:Access to a protected member _bar of a client class:HIGH +protected-access:213:12:Issue1159Subclass.access_other_attr:Access to a protected member _foo of a client class:HIGH +protected-access:232:8:Issue3066.foobar:Access to a protected member _attr of a client class:HIGH +protected-access:233:8:Issue3066.foobar:Access to a protected member _attr of a client class:HIGH +protected-access:236:8:Issue3066.foobar:Access to a protected member _bar of a client class:HIGH +protected-access:237:8:Issue3066.foobar:Access to a protected member _bar of a client class:HIGH +protected-access:247:12:Issue3066.Aclass.foobar:Access to a protected member _attr of a client class:HIGH +protected-access:249:12:Issue3066.Aclass.foobar:Access to a protected member _attr of a client class:HIGH +protected-access:251:12:Issue3066.Aclass.foobar:Access to a protected member _bar of a client class:HIGH +protected-access:253:12:Issue3066.Aclass.foobar:Access to a protected member _bar of a client class:HIGH +protected-access:267:16:Issue3066.Aclass.Bclass.foobar:Access to a protected member _attr of a client class:HIGH +protected-access:268:16:Issue3066.Aclass.Bclass.foobar:Access to a protected member _attr of a client class:HIGH +protected-access:271:16:Issue3066.Aclass.Bclass.foobar:Access to a protected member _bar of a client class:HIGH +protected-access:272:16:Issue3066.Aclass.Bclass.foobar:Access to a protected member _bar of a client class:HIGH |