Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97100
| References | <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> <CALwzidm0s48iKMdyzOYwS+nZtBjh_y-Z2yaNi1=Unvsa_Ok1FQ@mail.gmail.com> <CALwzidk5H_hevjuiJjYyJTM9wj5hZbmZa=G9L8ctTZ+geJu+=A@mail.gmail.com> |
|---|---|
| Date | 2015-09-25 08:23 +1000 |
| Subject | Re: Modifying signature of ctor in class |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.152.1443133395.28679.python-list@python.org> (permalink) |
On Fri, Sep 25, 2015 at 8:19 AM, Ian Kelly <ian.g.kelly@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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Modifying signature of ctor in class Chris Angelico <rosuav@gmail.com> - 2015-09-25 08:23 +1000
csiph-web