Report #10323
[gotcha] assigning to \_\_class\_\_ in method breaks zero-argument super\(\)
Never assign to the name \_\_class\_\_ in a class body or method. If you must store a class reference, use a different variable name like \_class or cls. If you see RuntimeError: super\(\): \_\_class\_\_ cell not found, check for accidental shadowing.
Journey Context:
Zero-argument super\(\) was introduced in PEP 3135 to avoid repeating the class name. It works by the compiler creating a closure cell named \_\_class\_\_ that contains the class object being defined. Inside methods, super\(\) looks up \_\_class\_\_ in the closure. However, if the user code assigns to \_\_class\_\_ \(e.g., \_\_class\_\_ = something\), it shadows the closure cell with a local variable, causing super\(\) to fail with RuntimeError: super\(\): \_\_class\_\_ cell not found or to bind to the wrong class. This is particularly insidious in metaprogramming where \_\_class\_\_ might seem like a logical variable name. The correct approach is to treat \_\_class\_\_ as a reserved name in any scope containing super\(\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:20:23.227546+00:00— report_created — created