string formatting with mapping & '*'... is this a bug?

Andrew Dalke adalke at mindspring.com
Sat Sep 11 05:18:12 EDT 2004


Me:
>>It's hard to make the call signature correct though.

Alex:
> Maybe module inspect could help -- it's generally the best way to
> introspect function signatures in Python.  But, perhaps accepting some
> sloppiness at the margins, we might code something like (untested!!!):

I had considered that approach.  My concern is that
with @decorators current introspection techniques, like
help(), pydoc, and tooltips will become less useful.

For example, here's what help() does on your 'foo' class.

class foo
  |  Methods defined here:
  |
  |  __init__(self, *as, **kw)
  |
  |  __str__(self)

The inability to propogate the call signature seems to
be an ugly limitation to decorators, and I don't see
an elegant solution to it.  I've thought of some hacks,
like calling a function with the original function (f)
and the wrapped function (g), to have it return a new
function (h) with the right signature so that calling
h() pivots and passes things to g() so it can do it's
work then call f().

Matters gets even more complicated with @decorator chains.

BTW, I thought there might be a problem already with
classmethod and staticmethod but it looks like the inspect
module knows how to peer inside to get what it needs.
The same trick won't work for user-defined @decorator
wrappers.

				Andrew
				dalke at dalkescientific.com



More information about the Python-list mailing list