PEP 840: Name Resolution in Class Namespaces
PEP 840 initiates a formal proposal process to standardize how variable names are resolved within Python class namespaces. It aims to eliminate long-standing inconsistencies in scope resolution rules during class definition.
Verified State Diff
Impact & Verification Analysis
Python core developers, library maintainers, and developers relying on complex class-level scope behaviors.
Standardizing name resolution reduces edge-case bugs and unexpected behavior in metaprogramming, class decorators, and complex inheritance patterns.
Full Fact Overview
The proposal addresses the technical debt associated with Python's class body execution model, where name resolution currently behaves differently than in function scopes or global modules. By formalizing the resolution logic, the Python Steering Council seeks to unify the behavior of name lookups, potentially altering how closures and nested scopes interact with class-level variables. This is a foundational architectural change that could impact the evaluation order and visibility of identifiers defined within the class body.