Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to a private function in inner class emits protected-access #3066

Closed
kown7 opened this issue Aug 15, 2019 · 2 comments · Fixed by #5232
Closed

Access to a private function in inner class emits protected-access #3066

kown7 opened this issue Aug 15, 2019 · 2 comments · Fixed by #5232
Labels
Bug 🪲 Minor 💅 Polishing pylint is always nice
Milestone

Comments

@kown7
Copy link

kown7 commented Aug 15, 2019

This issue might be related to #1159 and maybe others.

Steps to reproduce

The following code emits a W0212:

# pylint: disable=C0111, R0903


class Aclass:
    a = 42

    @staticmethod
    def foobar(i):
        Aclass._bar(i)

    @staticmethod
    def _bar(i):
        print(i)

    class Bclass:
        @staticmethod
        def foobar(i):
            Aclass.Bclass._bar(i)

        @staticmethod
        def _bar(i):
            print(i)


Aclass.foobar(Aclass.a + 3)
Aclass.Bclass.foobar(Aclass.a)

Current behavior

************* Module pylint_test
pylint_test.py:19:12: W0212: Access to a protected member _bar of a client class (protected-access)

Expected behavior

A solid 10/10 score.

pylint --version output

pylint 2.3.1
astroid 2.2.5
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]

@PCManticore
Copy link
Contributor

This is somewhat of an edge case as the check would need to be aware where this entire chain of objects is coming from.

@PCManticore PCManticore added Bug 🪲 Minor 💅 Polishing pylint is always nice labels Aug 16, 2019
@PCManticore PCManticore changed the title Access to a private function in inner class emits W0212 Access to a private function in inner class emits protected-access Aug 16, 2019
@kown7
Copy link
Author

kown7 commented Aug 17, 2019

I was unsure whether this is was a coding error on my side or not.

DanielNoord added a commit to DanielNoord/pylint that referenced this issue Oct 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.12.0 milestone Oct 30, 2021
Pierre-Sassoulas added a commit that referenced this issue Oct 31, 2021
…#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Minor 💅 Polishing pylint is always nice
Projects
None yet
3 participants