logoalt Hacker News

notepad0x9004/23/20251 replyview on HN

The naming convention is what is throwing me off. "object.closure" I understand as an attribute/property being accessed. In this case, the naming style suggests there should be a wrapper like:

def closure(self): return self.__closure__

I'm just talking form, not function here. In other words, if it is supposed to be accessed directly by arbitrary external code (non-class functions), it shouldn't use the double underscore syntax? If any property can have that syntax, then the syntax loses its meaning?


Replies

zahlman04/23/2025

>In other words, if it is supposed to be accessed directly by arbitrary external code

There is no such thing as "supposed to be" in this context. It can be accessed, because Python fundamentally doesn't protect against such accesses anywhere. There is no wrapper because there is no ordinary purpose for the access.

>If any property can have that syntax, then the syntax loses its meaning?

There is no special syntax here, so there is nothing that can lose meaning. Leading underscores are a convention. The parser doesn't care, and the compiler only makes minor adjustments (name mangling) in very limited circumstances (to avoid mistakes with subclasses).