This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Allow dataclasses.make_dataclass() to omit type information
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: eric.smith, gregory.p.smith, levkivskyi, rhettinger
Priority: normal Keywords: patch

Created on 2017-12-11 19:47 by eric.smith, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4982 closed gregory.p.smith, 2017-12-22 22:35
PR 5115 merged eric.smith, 2018-01-06 20:17
Messages (3)
msg308071 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-12-11 19:47
Make the typing information optional.

From Raymond Hettinger:

The make_dataclass() factory function in the dataclasses module currently requires type declarations. It would be nice if the type declarations were optional.

With typing (currently works):

    Point = NamedTuple('Point', [('x', float), ('y', float), ('z', float)])
    Point = make_dataclass('Point', [('x', float), ('y', float), ('z', float)])

Without typing (only the first currently works):

    Point = namedtuple('Point', ['x', 'y', 'z'])          # underlying store is a tuple
    Point = make_dataclass('Point', ['x', 'y', 'z'])      # underlying store is an instance dict
msg308583 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-12-18 20:32
I'm going to use "typing.Any" (as a string) if the type information is omitted in the call to make_dataclass(). That way I don't need to import typing.
msg309580 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-01-06 21:14
New changeset ed7d429ebb591f65cef558760fb4ebdc4fc8f8b0 by Eric V. Smith in branch 'master':
bpo-32278: Allow dataclasses.make_dataclass() to omit type information. (gh-5115)
https://github.com/python/cpython/commit/ed7d429ebb591f65cef558760fb4ebdc4fc8f8b0
History
Date User Action Args
2022-04-11 14:58:55adminsetgithub: 76459
2018-01-06 21:14:50eric.smithsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-01-06 21:14:05eric.smithsetmessages: + msg309580
2018-01-06 20:17:24eric.smithsetpull_requests: + pull_request4981
2017-12-22 22:38:50gregory.p.smithsetnosy: + gregory.p.smith
2017-12-22 22:35:45gregory.p.smithsetkeywords: + patch
stage: patch review
pull_requests: + pull_request4871
2017-12-18 20:32:16eric.smithsetmessages: + msg308583
2017-12-11 19:47:31eric.smithcreate