// HACKER NEWS — CYBERSECURITY
Python's pre-declared constants are kinda weird
python has 6 pre-declared "constants": True, False, None, __debug__, Ellipsis (or equivalently ...), and NotImplemented. but they all behave slightly differently, for some reason.
True, False, and None are keywords. they aren't identifiers, they're just straight up their own lexical tokens. which is really weird; nothing else is like this in python. usually stuff is resolved during regular name resolution, not in the lexer itself.
an interesting side effect of this is that expressions like x.True raise a SyntaxError. i'm curious as to what the rationale was for this decision (if there was one).
there's some more interesting stuff with these constants, but i'll get to it later, since it ties in with the other constants.
__debug__ is a boolean constant: it's normally True, but when running with -O, it's False. the idea is similar to how assert is disabled in non-debug builds: you can wrap code in if __debug__ if the check would be too expensive in an "optimized" build, or something.
__debug__ is really interesting though, because although it's a normal identifier (unlike True, False, and None), it's the only identifier in the language which can't be assigned to:
again, no other identifier behaves like this. this is a true special case.
but because it's not a keyword, it behaves slightly differently to True, False, and None:
x.__debug__ raises AttributeError (rather than SyntaxError), since it's syntactically valid; it's just looking up an attribute which doesn't exist.
interestingly, there's also a special error message for attempting to delete __debug__ (despite the fact that this would raise a NameError anyway if not for the special case), but this doesn't apply for deleting an attribute named __debug__:
if x were defined, an AttributeError would be raised instead. in either case, it's not a SyntaxError (unlike assignment), for some reason.