This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author doerwalter
Recipients doerwalter, r.david.murray
Date 2014-12-04.20:43:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1417725798.9.0.977944328507.issue22998@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-12-04 20:43:18doerwaltersetrecipients: + doerwalter, r.david.murray
2014-12-04 20:43:18doerwaltersetmessageid: <1417725798.9.0.977944328507.issue22998@psf.upfronthosting.co.za>
2014-12-04 20:43:18doerwalterlinkissue22998 messages
2014-12-04 20:43:18doerwaltercreate