Python's Constants Hide Compiler Tricks
A deep dive into Python’s six pre-declared constants—True, False, None, __debug__, Ellipsis, and NotImplemented—shows that they follow surprisingly different rules. Some are syntax-level keywords, one is compiler-special-cased, and others remain mutable builtins.
Python’s “constants” are less a coherent feature than a fossil record of language evolution. The quirks are mostly harmless, but they matter when introspection, metaprogramming, or debugging crosses the boundary between syntax and namespaces.
- –True, False, and None are lexical keywords, so they cannot be reassigned or used as attribute names. [Python documentation](https://docs.python.org/3/reference/expressions.html)
- –__debug__ behaves like a protected constant despite being an identifier, with assignment and deletion rejected at compile time.
- –Ellipsis and NotImplemented are ordinary builtin names that can be shadowed, while the ... literal still resolves to the canonical Ellipsis object.
- –The behavior reflects Python’s history and optimization choices more than a unified constant model, a useful reminder that language semantics often accumulate rather than emerge fully designed.
- –Developers should treat these names as implementation-sensitive primitives: use ... where possible, return NotImplemented only from supported special methods, and avoid mutating builtins.
DISCOVERED
1h ago
2026-08-26
PUBLISHED
4h ago
2026-08-25
RELEVANCE
AUTHOR
rbanffy