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 raises an exception if InitVar with default argument is not provided. #80651

Closed
GregKuhn mannequin opened this issue Mar 29, 2019 · 7 comments
Closed
Assignees
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@GregKuhn
Copy link
Mannequin

GregKuhn mannequin commented Mar 29, 2019

BPO 36470
Nosy @ericvsmith, @ilevkivskyi, @ZackerySpytz, @miss-islington, @mierzejk, @anthrotype
PRs
  • bpo-36470: Allow dataclasses.replace() to work InitVar with default values #17441
  • bpo-36470: Allow dataclasses.replace() to handle InitVars with default values #20867
  • [3.9] bpo-36470: Allow dataclasses.replace() to handle InitVars with default values (GH-20867) #25200
  • [3.8] bpo-36470: Allow dataclasses.replace() to handle InitVars with default values (GH-20867) #25201
  • 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 2021-04-05.20:12:35.465>
    created_at = <Date 2019-03-29.11:52:18.656>
    labels = ['interpreter-core', 'type-bug', '3.7']
    title = 'dataclasses.replace raises an exception if InitVar with default argument is not provided.'
    updated_at = <Date 2021-04-05.20:12:35.464>
    user = 'https://bugs.python.org/GregKuhn'

    bugs.python.org fields:

    activity = <Date 2021-04-05.20:12:35.464>
    actor = 'eric.smith'
    assignee = 'eric.smith'
    closed = True
    closed_date = <Date 2021-04-05.20:12:35.465>
    closer = 'eric.smith'
    components = ['Interpreter Core']
    creation = <Date 2019-03-29.11:52:18.656>
    creator = 'Greg Kuhn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36470
    keywords = ['patch']
    message_count = 7.0
    messages = ['339105', '339124', '385914', '390252', '390256', '390257', '390259']
    nosy_count = 7.0
    nosy_names = ['eric.smith', 'levkivskyi', 'ZackerySpytz', 'miss-islington', 'Greg Kuhn', 'mierzej', 'anthrotype']
    pr_nums = ['17441', '20867', '25200', '25201']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36470'
    versions = ['Python 3.7']

    @GregKuhn
    Copy link
    Mannequin Author

    GregKuhn mannequin commented Mar 29, 2019

    I have a snippet below which runs fine on python 3.7.0 but raises a ValueError exception on 3.7.1. I believe it's related to https://bugs.python.org/issue33805.

    The error: c:\python\lib\dataclasses.py:1219: ValueError

    The script:

    from dataclasses import replace, dataclass, InitVar
    
    @dataclass
    class Test:
        a:int = 1
        b:InitVar[int] = None
    
        def __post_init__(self, b):
            if b is not None:
                self.a = b
    
    
    if __name__ == '__main__':
        t = Test()
        t1 = Test(b=5)
        assert t1.a == 5
    
        t2 = replace(t1, **{})
        print(t2)

    @GregKuhn GregKuhn mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Mar 29, 2019
    @GregKuhn
    Copy link
    Mannequin Author

    GregKuhn mannequin commented Mar 29, 2019

    Fixed title

    @GregKuhn GregKuhn mannequin changed the title dataclasses replace raises an exception with an empty dataclasses.replace raises an exception if InitVar with default argument is not provided. Mar 29, 2019
    @ericvsmith ericvsmith self-assigned this Oct 1, 2019
    @anthrotype
    Copy link
    Mannequin

    anthrotype mannequin commented Jan 29, 2021

    any updates on this? Would be great if any of the two candidate PRs was merged. It's basically impossible to use replace() with default InitVars..
    Thank you in advace

    @miss-islington
    Copy link
    Contributor

    New changeset 7522067 by Zackery Spytz in branch 'master':
    bpo-36470: Allow dataclasses.replace() to handle InitVars with default values (GH-20867)
    7522067

    @ericvsmith
    Copy link
    Member

    New changeset bdee2a3 by Miss Islington (bot) in branch '3.8':
    bpo-36470: Allow dataclasses.replace() to handle InitVars with default values (GH-20867) (GH-25201)
    bdee2a3

    @ericvsmith
    Copy link
    Member

    New changeset 013c30e by Miss Islington (bot) in branch '3.9':
    bpo-36470: Allow dataclasses.replace() to handle InitVars with default values (GH-20867) (GH-25200)
    013c30e

    @ericvsmith
    Copy link
    Member

    Thanks for the fix!

    @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 interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants