attrs icon indicating copy to clipboard operation
attrs copied to clipboard

Pass kwargs to __attrs_pre_init__()

Open kevinphs opened this issue 1 year ago • 1 comments

This issue was closed but the args are passed in as positional arguments which isn't very helpful for my use case where there are a lot of fields and I only want to update one of them.

Can we also add support for passing in kwargs? Example:

def __attrs_pre_init__(self, **kwargs):
    ...
    super().__init__(**kwargs)
    ...

kevinphs avatar Jun 05 '24 21:06 kevinphs

Glancing at the code, ISTM that __attrs_pre_init__ is called the same way at __init__ so shouldn't:

def __attrs_pre_init__(self, *_, **kwargs):
    ...
    super().__init__(**kwargs)
    ...

just work? That presumes that all your arguments are kw-only, tho. If you're asking attrs to convert posargs into kwargs for this one call, I'm afraid that's out of scope.

hynek avatar Jun 26 '24 12:06 hynek