[New-bugs-announce] [issue35710] Make dataclasses.field() accept another name for __init__ field's name

Rémi Lapeyre report at bugs.python.org
Thu Jan 10 12:11:11 EST 2019


New submission from Rémi Lapeyre <remi.lapeyre at henki.fr>:

When creating a class, I sometimes wish to get this behavior:


    def MyClass:
        def __init__(self, param):
            self._param = param

        def __repr__(self):
            return f"MyClass(param={self._param})"


Unless I'm making a mistaking, this behavior is not currently possible with dataclasses.

I propose to change:

    field(*, default=MISSING, default_factory=MISSING, repr=True, hash=None, init=True, compare=True, metadata=None)

to: 

    field(*, default=MISSING, default_factory=MISSING, repr=True, hash=None, init=True, compare=True, metadata=None, target=None)

with target being used as the init parameter name for this field and in the repr.

If this is accepted, I can post the patch to make this change.

----------
messages: 333409
nosy: remi.lapeyre
priority: normal
severity: normal
status: open
title: Make dataclasses.field() accept another name for __init__ field's name
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35710>
_______________________________________


More information about the New-bugs-announce mailing list