[Python-Dev] Review of PEP 362 (signature object)

Nick Coghlan ncoghlan at gmail.com
Tue Mar 13 02:12:34 CET 2012

On Tue, Mar 13, 2012 at 10:51 AM, Guido van Rossum <guido at python.org> wrote:
> - I don't quite understand how bind() is supposed to work. Maybe an
> example would help? (It could also use some motivation. I think this
> is meant to expose a canonical version of the algorithm that maps
> arguments to parameters. What's a use case?)

I can help with that part: one use case is to give early errors for
bad arguments to delayed calls. Currently, if you have a delayed call
(e.g. a callback of some kind) that accepts (callable, *args, **kwds),
there's no parameter checking until the call actually happens. That
can lead to quite a debugging hunt as you try to track down where the
bad callback was originally registered.

However, with bind() available, you can do an initial sanity check
that the arguments can at least be used to invoke the callable,
throwing an error on *registration* if the callback is simply never
going to work.

Another use case is more sophisticated protocol checking than a simple
hasattr() check for a method name - you can check that the method will
accept the arguments you want to pass, not just whether it exists or
not. (For example, this can help generate better error messages if a
protocol evolves to accept additional optional arguments, but
supporting those arguments is *required* for a particular application)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list