You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, kwargs are "converted" to positional arguments which in my case causes the error because kwarg1 cannot be used as a positional argument but only a keyword argument.
A possible fix would be to check the kind of the parameter and construct a kwargs dictionary with all keyword-only arguments. This, for example, works in my case:
def_apply_defaults(func, args, kwargs):
"""Apply default keyword arguments. Named keywords may have been left blank. This function applies the default values so that every argument is defined. """sig=signature(func)
bound_arguments=sig.bind(*args, **kwargs)
forparaminsig.parameters.values():
ifparam.namenotinbound_arguments.arguments:
bound_arguments.arguments[param.name] =param.defaultargs= []
kwargs= {}
forkey, paraminsig.parameters.items():
ifparam.kind==Parameter.KEYWORD_ONLY:
kwargs[key] =bound_arguments.arguments[key]
else:
args.append(bound_arguments.arguments[key])
returnargs, kwargs
The text was updated successfully, but these errors were encountered:
FMeinicke
changed the title
wraps does not correctly handle keyword only arguments
wraps does not correctly handle keyword-only arguments
Mar 14, 2023
I have a function that takes some positional arguments and a keyword-only argument that I'd like to wrap with
@ureg.wraps
as follows:However, this results in the following error:
I've traced the problem down to this function:
pint/pint/registry_helpers.py
Lines 173 to 186 in 5314065
Here,
kwargs
are "converted" to positional arguments which in my case causes the error becausekwarg1
cannot be used as a positional argument but only a keyword argument.A possible fix would be to check the
kind
of the parameter and construct akwargs
dictionary with all keyword-only arguments. This, for example, works in my case:The text was updated successfully, but these errors were encountered: