Modifying signature of ctor in class

Chris Angelico rosuav at gmail.com
Fri Sep 25 00:23:12 CEST 2015


On Fri, Sep 25, 2015 at 8:19 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> Quick and dirty example:
>
> py> from inspect import Signature, Parameter
> py> def foo(*args, **kwargs): pass
> ...
> py> foo.__signature__ = Signature([Parameter('x',
> Parameter.POSITIONAL_OR_KEYWORD), Parameter('y',
> Parameter.KEYWORD_ONLY)])
> py> help(foo)
> Help on function foo in module __main__:
>
> foo(x, *, y)

Okay, that's a LOT easier than the stuff I was playing around with :)

Of course, it still requires that inspect.signature be used.

ChrisA


More information about the Python-list mailing list