-
Notifications
You must be signed in to change notification settings - Fork 25
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
functions with kwargs #114
Comments
Would you mind submitting a PR? |
To be honest, I do not know how much the following fix would destroy, but a possible fix could be: # <Signature (a, b, c, d=4)>
signature = inspect.signature(func, follow_wrapped=False)
# func(y, x, c=z)
# ['y', 'x'], {'c': 'z'}
arg_sources = [
argnode_source(source, argnode, vars_only) for argnode in node.args
]
kwarg_sources = {
argnode.arg: argnode_source(source, argnode.value, vars_only)
for argnode in node.keywords
if argnode.arg is not None
}
- bound_args = signature.bind_partial(*arg_sources, **kwarg_sources)
+ bound_args = signature.bind_partial(*arg_sources, *kwarg_sources.values())
argument_sources = bound_args.arguments An alternative (quick and dirty) fix, which ignores all kwargs, would be to adjust the final signature of def nameof(
var: Any,
*more_vars: Any,
frame: int = 1,
vars_only: bool = True,
+ **kwargs,
) -> Union[str, Tuple[str, ...]]: I could look further into it if issue #115 is solved. |
Since |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The signature binding fails if the function contains
kwarg_sources
.Reproduce
Traceback
Problem
If I am not mistaken, the issue lies in line 442:
python-varname/varname/utils.py
Lines 431 to 442 in 1e07fce
The
signature
here is thenameof
function:<Signature (var: Any, *more_vars: Any, frame: int = 1, vars_only: bool = True) -> Union[str, Tuple[str, ...]]>
and therefore does not take anykwarg_sources
from the source functionfn
.Workaround
None, as far as I know.
The text was updated successfully, but these errors were encountered: