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

protected-access and @classmethod cls #1159

Closed
alvarocaceres opened this issue Nov 7, 2016 · 8 comments · Fixed by #4267
Closed

protected-access and @classmethod cls #1159

alvarocaceres opened this issue Nov 7, 2016 · 8 comments · Fixed by #4267
Assignees
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@alvarocaceres
Copy link

Steps to reproduce

class C(object):
  _Foo = 12

  @classmethod
  def Enable(cls):
    x = cls()
    print x._Foo  # protected-access warning

Current behavior

W: 7,10: Access to a protected member _Foo of a client class (protected-access)

Expected behavior

Seems like this should be allowed, for consistency with regular methods

pylint --version output

No config file found, using default configuration
pylint 2.0.0, 
astroid 1.5.0
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2]

@Paebbels
Copy link

Paebbels commented Dec 5, 2016

I'm using Landscape.io, which uses pylint to check my Python code. I reported there another example for a falsely reported access to a protected member. See Landscape falsely reports an access to protected members for more details.

Note my presented example uses type hints, which are not evaluated by pylint as it seems.

@mkielg11
Copy link

mkielg11 commented Nov 5, 2020

I get this error with pylint version 2.5.3 on Python 3.8.0, is this in the pipeline of getting fixed?

@hippo91
Copy link
Contributor

hippo91 commented Nov 17, 2020

@mkielg11 can you give us a snippet of your issue please?
Thanks.

@mkielg11
Copy link

mkielg11 commented Dec 17, 2020

@mkielg11 can you give us a snippet of your issue please?
Thanks.

Well, yes, sorry @hippo91 for long reply time. The example is, however, exactly as above:

class TestClass:
    _test_var = 0

    @classmethod
    def test_class_method(cls):
        instance = cls()
        instance._test_var = 40
        return instance

Result:
W0212: Access to a protected member _test_var of a client class (protected-access)

> pylint --version
pylint 2.5.3
astroid 2.4.2
Python 3.8.5

@hippo91
Copy link
Contributor

hippo91 commented Dec 20, 2020

@mkielg11 thanks for your snippet. I can reproduce it. Unfortunately nobody has been interested in fixing this bug.
What about trying to fix this?

@mkielg11
Copy link

@mkielg11 thanks for your snippet. I can reproduce it. Unfortunately nobody has been interested in fixing this bug.
What about trying to fix this?

You mean that I could propose a fix? I guess I may be able to, however, I have no insight in the pylint source code, so I think I'll pass on that.

@irgeek
Copy link
Contributor

irgeek commented Mar 22, 2021

This is one bug that irks me enough I'd like to have a crack at solving it. I haven't worked with the codebase before, though, so I'm not sure where to start. Is there a getting-started guide or something similar that would help me in figuring out where to start fixing this?

@Pierre-Sassoulas
Copy link
Member

Sure thing @irgeek thank you for willing to contribute, I assigned you to the issue. You can find the developper doc here: http://pylint.pycqa.org/en/latest/development_guide/contribute.html

@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants