Elektrine lite

← Feed

@YesJustWolf@hachyderm.io

2026-07-23 13:40 UTC

@cartocalypse When you define things in Python, either you want others to see them or not. A single initial underscore is one of the things that gently communicates "this is not for you". Omitting it from __init__.py is another. No protection is afforded by the Python itself. If you require enforcement, you’re in the wrong language, sorry. Given that, now the ball is in the consumer’s court: do they know what you meant. In general, an initial underscore tells them the thing they need to know. Double underscore (prefix only) is unusual. Double underscore at both ends is reserved for system related symbols. You sometimes define them. You rarely call them. Are you trying to tell the user something? Or do you want to actually prevent it? If you’re dead set on the latter then __getattr__ tricks or maybe modules written in Rust or C++ or whatever can get you there while remaining mostly in Python, but it’s not usually worth the trouble. The Pythonic way is cooperation. If you are trying to sidestep this, you’re not really walking in Python’s footsteps.

Replies (0)

No replies.