Just don't use the "__" in the class variable name and you are set.
Some Python write ups and "documentation" say that the "__" prefix is the Python way to get "private" members in a class. They are wrong.
The "__" prefix does exactly what is happening to you: ensure that the variable accessed in a method inside a class access the variable defined in that exact class (and not any of the classes that inherit from it).
The way it works is simple: at compile time, the names prefixed with "__" are "mangled", i.e. changed like this: __much
-> _classname__much
:
>>> class Hidden(object):
... __hidden = False
...
>>> dir(Hidden)
['_Hidden__hidden', '__class__', ...]
Therefore your getHidden
method will always look for the __much
variable thathas had its name actually changed to _MySuperInterface__much
, while the variable you want has had its name changed to _MySub__much
.
If you as much as use a single underscore "_" to mean by convention the variable should not be used outside of the class, your code would work as you expect.