gh-85795: Raise a clear error when super() is used in typing.NamedTuple subclasses (#130082)

This commit is contained in:
Bartosz Sławecki 2025-03-06 05:45:47 +01:00 committed by GitHub
parent 5e73ece95e
commit 293fa3433e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 0 deletions

View file

@ -2889,6 +2889,9 @@ _special = frozenset({'__module__', '__name__', '__annotations__', '__annotate__
class NamedTupleMeta(type):
def __new__(cls, typename, bases, ns):
assert _NamedTuple in bases
if "__classcell__" in ns:
raise TypeError(
"uses of super() and __class__ are unsupported in methods of NamedTuple subclasses")
for base in bases:
if base is not _NamedTuple and base is not Generic:
raise TypeError(