mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-40185: Refactor typing.NamedTuple (GH-19371)
This commit is contained in:
parent
307b9d0144
commit
a2ec06938f
2 changed files with 53 additions and 58 deletions
|
@ -3598,11 +3598,9 @@ class NamedTupleTests(BaseTestCase):
|
|||
self.assertEqual(CoolEmployeeWithDefault._field_defaults, dict(cool=0))
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
exec("""
|
||||
class NonDefaultAfterDefault(NamedTuple):
|
||||
x: int = 3
|
||||
y: int
|
||||
""")
|
||||
class NonDefaultAfterDefault(NamedTuple):
|
||||
x: int = 3
|
||||
y: int
|
||||
|
||||
def test_annotation_usage_with_methods(self):
|
||||
self.assertEqual(XMeth(1).double(), 2)
|
||||
|
@ -3611,20 +3609,16 @@ class NonDefaultAfterDefault(NamedTuple):
|
|||
self.assertEqual(XRepr(1, 2) + XRepr(3), 0)
|
||||
|
||||
with self.assertRaises(AttributeError):
|
||||
exec("""
|
||||
class XMethBad(NamedTuple):
|
||||
x: int
|
||||
def _fields(self):
|
||||
return 'no chance for this'
|
||||
""")
|
||||
class XMethBad(NamedTuple):
|
||||
x: int
|
||||
def _fields(self):
|
||||
return 'no chance for this'
|
||||
|
||||
with self.assertRaises(AttributeError):
|
||||
exec("""
|
||||
class XMethBad2(NamedTuple):
|
||||
x: int
|
||||
def _source(self):
|
||||
return 'no chance for this as well'
|
||||
""")
|
||||
class XMethBad2(NamedTuple):
|
||||
x: int
|
||||
def _source(self):
|
||||
return 'no chance for this as well'
|
||||
|
||||
def test_multiple_inheritance(self):
|
||||
class A:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue