Added kw_only parameter to make_dataclasses. (GH-29679)

(cherry picked from commit f7638dd0f9)

Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2021-11-20 15:46:56 -08:00 committed by GitHub
parent 3528df1258
commit cf8c8788c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View file

@ -3864,5 +3864,16 @@ class TestKeywordArgs(unittest.TestCase):
c: int = 1
d: int
def test_make_dataclass(self):
A = make_dataclass("A", ['a'], kw_only=True)
self.assertTrue(fields(A)[0].kw_only)
B = make_dataclass("B",
['a', ('b', int, field(kw_only=False))],
kw_only=True)
self.assertTrue(fields(B)[0].kw_only)
self.assertFalse(fields(B)[1].kw_only)
if __name__ == '__main__':
unittest.main()