3 ms·
I think it would be a good idea to consider name-mangled attributes (https://docs.python.org/3/tutorial/classes.html#private-variables https://docs.python.org/3
by zahlman 2y ago
I think it would be a good idea to consider name-mangled attributes (https://docs.python.org/3/tutorial/classes.html#private-variables https://docs.python.org/3/tutorial/classes.html#private-vari... ; https://stackoverflow.com/questions/7456807 https://stackoverflow.com/questions/7456807) separately:
>>> class x:
... def __foo(self): pass
...
>>> dir(x) # word-wrapped manually to protect your eyes
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__',
'__hash__', '__init__', '__init_subclass__', '__le__', '__lt__',
'__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
'__weakref__', '_x__foo']
`__foo` is probably not meant for external use, but the real reason to use the leading double underscore is to invoke that name mangling and thus avoid name collisions in subclasses. Some people do still use this feature. (These days, I barely even use inheritance.)
Perhaps it could use the same colour for the `_x` as for other single-underscore names, and a fourth colour for the `__foo` part.