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

dataclasses.replace() fails with the field named "obj" #81344

Closed
serhiy-storchaka opened this issue Jun 5, 2019 · 8 comments
Closed

dataclasses.replace() fails with the field named "obj" #81344

serhiy-storchaka opened this issue Jun 5, 2019 · 8 comments
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 37163
Nosy @brettcannon, @ericvsmith, @serhiy-storchaka, @pablogsal
PRs
  • [3.8] bpo-37163: Deprecate passing argument obj of dataclasses.replace() by keyword. #13877
  • bpo-37163: Make the obj argument of dataclasses.replace() a positional-only. #14390
  • [3.7] bpo-37163: dataclasses.replace() now supports the field named "obj". (GH-13877) #14405
  • 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 = None
    closed_at = <Date 2019-06-26.20:16:55.693>
    created_at = <Date 2019-06-05.11:13:04.903>
    labels = ['3.7', '3.8', 'type-bug', 'library', '3.9']
    title = 'dataclasses.replace() fails with the field named "obj"'
    updated_at = <Date 2019-06-26.20:16:55.692>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2019-06-26.20:16:55.692>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-06-26.20:16:55.693>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2019-06-05.11:13:04.903>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37163
    keywords = ['patch']
    message_count = 8.0
    messages = ['344704', '344707', '344741', '344751', '344896', '346022', '346647', '346674']
    nosy_count = 4.0
    nosy_names = ['brett.cannon', 'eric.smith', 'serhiy.storchaka', 'pablogsal']
    pr_nums = ['13877', '14390', '14405']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37163'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @serhiy-storchaka
    Copy link
    Member Author

    >>> from dataclasses import *
    >>> @dataclass
    ... class D:
    ...     obj: object
    ... 
    >>> replace(D(123), obj='abc')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: replace() got multiple values for argument 'obj'

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jun 5, 2019
    @ericvsmith
    Copy link
    Member

    Possibly a use for positional-only parameters. Backward compatibility is the question, of course.

    @serhiy-storchaka
    Copy link
    Member Author

    I propose to add a deprecation warning in 3.8 and use the PEP-570 syntax in 3.9 (which means a TypeError if obj is passed by keyword argument).

    @brettcannon
    Copy link
    Member

    +1 for Serhiy's suggestion

    @pablogsal
    Copy link
    Member

    +1 to Serhiy's proposal

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset f5b89af by Serhiy Storchaka in branch '3.8':
    bpo-37163: Deprecate passing argument obj of dataclasses.replace() by keyword. (GH-13877)
    f5b89af

    @pablogsal pablogsal reopened this Jun 25, 2019
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 2d88e63 by Serhiy Storchaka in branch 'master':
    bpo-37163: Make the obj argument of dataclasses.replace() a positional-only. (GH-14390)
    2d88e63

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 6ef103f by Serhiy Storchaka in branch '3.7':
    [3.7] bpo-37163: dataclasses.replace() now supports the field named "obj". (GH-13877) (GH-14405)
    6ef103f

    @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 3.8 (EOL) end of life 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants