You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Even though other is clearly a member of the same class MyClass 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:
"Used when a protected member (i.e. class member with a name beginning with an underscore) is access outside the class or a descendant of the class where it's defined."
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:
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?
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
The text was updated successfully, but these errors were encountered: