mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
bpo-32278: Allow dataclasses.make_dataclass() to omit type information. (gh-5115)
This commit is contained in:
parent
e7ba013d87
commit
ed7d429ebb
3 changed files with 30 additions and 6 deletions
|
@ -2033,6 +2033,20 @@ class TestCase(unittest.TestCase):
|
|||
self.assertEqual(C.y, 10)
|
||||
self.assertEqual(C.z, 20)
|
||||
|
||||
def test_helper_make_dataclass_no_types(self):
|
||||
C = make_dataclass('Point', ['x', 'y', 'z'])
|
||||
c = C(1, 2, 3)
|
||||
self.assertEqual(vars(c), {'x': 1, 'y': 2, 'z': 3})
|
||||
self.assertEqual(C.__annotations__, {'x': 'typing.Any',
|
||||
'y': 'typing.Any',
|
||||
'z': 'typing.Any'})
|
||||
|
||||
C = make_dataclass('Point', ['x', ('y', int), 'z'])
|
||||
c = C(1, 2, 3)
|
||||
self.assertEqual(vars(c), {'x': 1, 'y': 2, 'z': 3})
|
||||
self.assertEqual(C.__annotations__, {'x': 'typing.Any',
|
||||
'y': int,
|
||||
'z': 'typing.Any'})
|
||||
|
||||
class TestDocString(unittest.TestCase):
|
||||
def assertDocStrEqual(self, a, b):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue