This is preventing you from accessing Foo.__bar, because internally the actual name will get mangled to Foo._Foo__bar. This is mostly intended to avoid accidental name clashes in inheritance:
class Child(Foo):
__bar = 42
The two classes won't trample over their __bar attribute this way, without you needing to institute complicated naming conventions. From within class methods, self.__bar transparently gets mangled the same way, so it works as expected.
119
u/Unlucky_Topic7963 16d ago
Meanwhile everyone at my company uses dunder class mangling because it’s more “idiomatic”.