Closed bshoshany closed 2 months ago
Thanks for the report. The essence of the issue in this case is that pylint doesn't trust type annotations. There's an obvious value prop there for poorly or untyped projects.
Thanks so much for your fast response! If I understand correctly, you are saying that Pylint doesn't trust the type annotation saying that other
is of type Self
(or MyClass
) because it might be wrong if this is a poorly-typed project. If I may ask, what about well-typed projects, where the user spends hours ensuring all type annotations are correct (guilty...), and therefore this is indeed a clear false positive, as in the example above? Perhaps there can at least be some kind of flag that tells Pylint to trust the user's type annotations?
These are good questions, and they can be explored more fully on #4813 in a context broader than just this message 👍 .
Bug description
Pylint seems to be reporting a false positive, unless I'm misunderstanding something about how classes work. Here is a minimal example:
Even though
other
is clearly a member of the same classMyClass
based on the type annotation, Pylint complains about "Access to a protected member _private of a client class" with error code "protected-access / W0212". Looking at the error code description, it says:Clearly,
_private
is being accesses from inside the class where it's defined, so this appears to be a false positive. Even type-annotating the class explicitly doesn't help:Now the
other
object is explicitly defined as being an instance ofMyClass
, but Pylint still complains about access to a protected member.Configuration
No response
Command used
Pylint output
Expected behavior
Any method in the class
MyClass
should be able to access the class's private members on any instance of that very same class.Pylint version
OS / Environment
Windows 11
Additional dependencies
No response