bpo-32278: Allow dataclasses.make_dataclass() to omit type information. (gh-5115)

This commit is contained in:
Eric V. Smith 2018-01-06 16:14:03 -05:00 committed by GitHub
parent e7ba013d87
commit ed7d429ebb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 6 deletions

View file

@ -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):