johnslavik ยท GitHub

Follow-up to conclusions from gh-129352, closes gh-85795.

In #129352 (comment), @rhettinger and I agreed that a clear error message is needed when a user attempts to use super() in typing.NamedTuple subclasses.

I believe this PR should be backported. Since we no longer raise a RuntimeError, this cannot be backported.

About the PR

Pure presence of __classcell__ is enough to confirm that __class__ closure was created to enable super() calls.

Tests for cases where __classcell__ are manually set in typed named tuples were intentionally not added, as I don't see the value in considering these behaviors.

Interestingly, I used a note admonition instead of .. versionchanged:: next in the docs and it's completely backward-compatible: it applies to all relevant previous versions of Python. I considered making an "important" block instead, but I think super() is not often enough to support that idea. No longer true, we raise TypeError instead of RuntimeError

CC previous reviewers: @ZeroIntensity @AlexWaygood @JelleZijlstra @rhettinger


๐Ÿ“š Documentation preview ๐Ÿ“š: https://cpython-previews--130082.org.readthedocs.build/

Read the original on github.com โ†—