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. __de
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 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…
saved by
related reading
- styleguide | Style guides for Google-originated open-source projectsgoogle.github.io
- GitHub - pablogsal/python-horror-show: Strange and odd python snippets explainedgithub.com
- Programming FAQ — Python 3.14.6 documentationdocs.python.org
- PEP 20 – The Zen of Python | peps.python.orgpeps.python.org
- Pyrefly vs. ty: Comparing Python’s Two New Rust-Based Type Checkers | Edward Li's Blogblog.edward-li.com
- Constants and statics - Rust for C-Programmersrust-for-c-programmers.com
- 9. Kaleidoscope: Adding Debug Information — LLVM 23.0.0git documentationllvm.org
- Glossary — Python 3.14.6 documentationdocs.python.org
- Built-in Functions — Python 3.14.6 documentationdocs.python.org
- "We're building a new static type checker for Python" | Hacker Newsnews.ycombinator.com
- P2900R13.pdfisocpp.org
- cpython/Objects/abstract.c at 3.10 · python/cpython · GitHubgithub.com