PEP 840: Name Resolution in Class Namespaces

I looked into this behavior in some detail when I worked on PEP 695: see my post at Implementing PEP 695 | Jelle Zijlstra and some of the examples in my PyCon talk a few years ago (slides at https://jellezijlstra.github.io/talks/pycon2024-pep695.pdf from slide 34 onward).

The current class scoping behavior is indeed questionable, but the practical impact seems limited and changing a core language behavior is always risky. Therefore, I’d lean towards making no changes and documenting the existing behavior.

A useful discussion to look at would be PEP 709: one behavior change that was missed in the PEP, where we discussed another subtle change related to class scopes. There we gathered some evidence from open source code to see how common the affected kind of code was in the wild.

6 Likes