Missing Feature: Refactoring of external references for private variables

Answered

Hi everyone,

for certain use cases it is a common practise or even required to use private variables in Python, e.g., in larger Python projects and libraries they can help to further hide away the inner complexity of code form users. Referencing such variables or methods from outside is provided as show below in the last line of code and described in PEP 8.

Unfortunately and to my very best knowledge, PyCharm does not yet support refactoring external references to private variables, e.g. renaming __private_foo of class A will not effect the valid reference _A__private_foo

If this is not yet supported, I would hereby like to propose to support the "Refactoring of external references for private variables", and if, I would kindly ask for advice on how can trigger PyCharm to support me in refactoring them?

class A:
def __init__(self):
self.__private_foo = 1
def foo():
return self.__private_foo

a = A()
print(a._A__private_foo)
0
2 comments

Aside of refatoring: PyCharm does not yet recognize references like _A__private_foo but claims it to be an "Unresolved attribute reference '_A__private_foo' for class A." If A is already properly recognized to be the referenced parent class, why not  its attribute __private_foo?

I'm not asking for A.__private_foo to be recognized but just _A__private_foo as an explicit reference to an otherwise private attribute.

0

Please sign in to leave a comment.