Skip to content

Rename dataclass's __replace__ argument from "obj" to "self"? #114198

Closed

Description

@pschanely

Bug report

Bug description:

The first argument of the new __replace__ method on dataclasses is conspicuously named obj rather than self. While that's not a bug, it would be kinder on introspection tools to use self, since it is otherwise a regular instance method.

>>> import dataclasses, inspect, pprint
>>> @dataclasses.dataclass
... class Foo:
...   x: int
... 
>>> pprint.pprint({n:inspect.signature(f) for n, f in inspect.getmembers(Foo, inspect.isfunction)})
{'__eq__': <Signature (self, other)>,
 '__init__': <Signature (self, x: int) -> None>,
 '__replace__': <Signature (obj, /, **changes)>,
 '__repr__': <Signature (self)>}

__replace__ was added in #108752

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Jan 17, 2024
  2. serhiy-storchaka commented on Jan 17, 2024

    @serhiy-storchaka
    Member

    It is a trivial change. You just need to rename a parameter of function _replace() in dataclasses module.

  3. ericvsmith commented on Jan 18, 2024

    @ericvsmith
    Member

    @pschanely : Do you want to make a PR?

  4. pschanely commented on Jan 18, 2024

    @pschanely
    ContributorAuthor

    @pschanely : Do you want to make a PR?

    Oh. Well, I haven't contributed to cpython before, but I'm willing to give it a try.

  5. ericvsmith commented on Jan 18, 2024

    @ericvsmith
    Member

    @pschanely : Reach out if you need any help!

  6. added a commit that references this issue on Jan 18, 2024
  7. ericvsmith commented on Jan 18, 2024

    @ericvsmith
    Member

    Thanks, @pschanely !

  8. added a commit that references this issue on Jan 22, 2024
  9. added a commit that references this issue on Feb 11, 2024
  10. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

easytype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions