Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dataclasses.make_dataclass() to omit type information #76459

Closed
ericvsmith opened this issue Dec 11, 2017 · 3 comments
Closed

Allow dataclasses.make_dataclass() to omit type information #76459

ericvsmith opened this issue Dec 11, 2017 · 3 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ericvsmith
Copy link
Member

BPO 32278
Nosy @rhettinger, @gpshead, @ericvsmith, @ilevkivskyi
PRs
  • bpo-32278: Add dataclasses.Data as an alias for typing.Any #4982
  • bpo-32278: Allow dataclasses.make_dataclass() to omit type information. #5115
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ericvsmith'
    closed_at = <Date 2018-01-06.21:14:50.072>
    created_at = <Date 2017-12-11.19:47:31.276>
    labels = ['3.7', 'type-bug', 'library']
    title = 'Allow dataclasses.make_dataclass() to omit type information'
    updated_at = <Date 2018-01-06.21:14:50.071>
    user = 'https://github.com/ericvsmith'

    bugs.python.org fields:

    activity = <Date 2018-01-06.21:14:50.071>
    actor = 'eric.smith'
    assignee = 'eric.smith'
    closed = True
    closed_date = <Date 2018-01-06.21:14:50.072>
    closer = 'eric.smith'
    components = ['Library (Lib)']
    creation = <Date 2017-12-11.19:47:31.276>
    creator = 'eric.smith'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32278
    keywords = ['patch']
    message_count = 3.0
    messages = ['308071', '308583', '309580']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'gregory.p.smith', 'eric.smith', 'levkivskyi']
    pr_nums = ['4982', '5115']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32278'
    versions = ['Python 3.7']

    @ericvsmith
    Copy link
    Member Author

    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

    @ericvsmith ericvsmith added the 3.7 (EOL) end of life label Dec 11, 2017
    @ericvsmith ericvsmith self-assigned this Dec 11, 2017
    @ericvsmith ericvsmith added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 11, 2017
    @ericvsmith
    Copy link
    Member Author

    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.

    @ericvsmith
    Copy link
    Member Author

    New changeset ed7d429 by Eric V. Smith in branch 'master':
    bpo-32278: Allow dataclasses.make_dataclass() to omit type information. (gh-5115)
    ed7d429

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant