mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-32279: Add additional params to make_dataclass(), pass through to dataclass(). (gh-5117)
This commit is contained in:
parent
ed7d429ebb
commit
d80b443f02
3 changed files with 26 additions and 3 deletions
|
@ -2033,6 +2033,23 @@ class TestCase(unittest.TestCase):
|
|||
self.assertEqual(C.y, 10)
|
||||
self.assertEqual(C.z, 20)
|
||||
|
||||
def test_helper_make_dataclass_other_params(self):
|
||||
C = make_dataclass('C',
|
||||
[('x', int),
|
||||
('y', ClassVar[int], 10),
|
||||
('z', ClassVar[int], field(default=20)),
|
||||
],
|
||||
init=False)
|
||||
# Make sure we have a repr, but no init.
|
||||
self.assertNotIn('__init__', vars(C))
|
||||
self.assertIn('__repr__', vars(C))
|
||||
|
||||
# Make sure random other params don't work.
|
||||
with self.assertRaisesRegex(TypeError, 'unexpected keyword argument'):
|
||||
C = make_dataclass('C',
|
||||
[],
|
||||
xxinit=False)
|
||||
|
||||
def test_helper_make_dataclass_no_types(self):
|
||||
C = make_dataclass('Point', ['x', 'y', 'z'])
|
||||
c = C(1, 2, 3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue