mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-85795: Raise a clear error when super()
is used in typing.NamedTuple
subclasses (#130082)
This commit is contained in:
parent
5e73ece95e
commit
293fa3433e
4 changed files with 27 additions and 0 deletions
|
@ -8349,6 +8349,23 @@ class NamedTupleTests(BaseTestCase):
|
|||
class Foo(NamedTuple):
|
||||
attr = very_annoying
|
||||
|
||||
def test_super_explicitly_disallowed(self):
|
||||
expected_message = (
|
||||
"uses of super() and __class__ are unsupported "
|
||||
"in methods of NamedTuple subclasses"
|
||||
)
|
||||
|
||||
with self.assertRaises(TypeError, msg=expected_message):
|
||||
class ThisWontWork(NamedTuple):
|
||||
def __repr__(self):
|
||||
return super().__repr__()
|
||||
|
||||
with self.assertRaises(TypeError, msg=expected_message):
|
||||
class ThisWontWorkEither(NamedTuple):
|
||||
@property
|
||||
def name(self):
|
||||
return __class__.__name__
|
||||
|
||||
|
||||
class TypedDictTests(BaseTestCase):
|
||||
def test_basics_functional_syntax(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue