I see a lot of python code that does "loose" private variables / functions. They'll declare functions / variables with one underscore (eg. _foo) and then use it just in the class / file. It really annoys me that they don't use the double underscore because eventually, someone will call this "private" member from outside the class.
Is there some way to enforce the privacy on single underscores (without changing to doubles)? Thanks!
__has special significance. It mangles the names, makes debugging difficult and can lead to interesting issues with introspection. Your "loose" privacy is really all there is that makes sense. Who is this mysterious "someone" who will violate basic Python rules? And when the unit tests fail because they broke the rules, what more is needed? They violated the API and a test failed. Isn't that enough?private: docs.python.org/tutorial/classes.html#tut-private