Walter Dörwald added the comment: The following doesn't work::
import inspect def foo(*args, **kwargs): return (args, kwargs) # Code from https://docs.python.org/3/library/inspect.html#inspect.BoundArguments.arguments to fill in the defaults sig = inspect.signature(foo) ba = sig.bind() for param in sig.parameters.values(): if param.name not in ba.arguments: ba.arguments[param.name] = param.default print(foo(*ba.args, **ba.kwargs)) instead it gives the following traceback:: Traceback (most recent call last): File "sig_test.py", line 16, in <module> print(foo(*ba.args, **ba.kwargs)) File "/Users/walter/.local/lib/python3.4/inspect.py", line 2246, in args args.extend(arg) TypeError: 'type' object is not iterable In my use case there isn't a call to a function implemented in Python. Instead I'm implementing a templating languages that supports defining a signature for a template. Calling the template binds the arguments and inside the template the variables simply are a dictionary. I.e. define the template like this: t = Template("<?print a+b?>", signature="a, b=23") Then you can call it like this: t(17) and inside the template the variables will be {"a": 17, "b": 23}. The signature argument in the Template constructor will be parsed into an inspect.Signature object and I'd like to use Signature.bind() to get the final variables dictionary. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22998> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com