Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97093 > unrolled thread

Re: Modifying signature of ctor in class

Started byChris Angelico <rosuav@gmail.com>
First post2015-09-25 07:38 +1000
Last post2015-09-25 07:38 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Modifying signature of ctor in class Chris Angelico <rosuav@gmail.com> - 2015-09-25 07:38 +1000

#97093 — Re: Modifying signature of ctor in class

FromChris Angelico <rosuav@gmail.com>
Date2015-09-25 07:38 +1000
SubjectRe: Modifying signature of ctor in class
Message-ID<mailman.145.1443130747.28679.python-list@python.org>
On Fri, Sep 25, 2015 at 6:28 AM, Joseph L. Casale
<jcasale@activenetwerx.com> wrote:
> I have a class factory where I dynamically add a constructor to the class output.
> The method is a closure and works just fine, however to accommodate the varied
> input its signature is (*args, **kwargs).
>
> While I modify the doc strings, the ctor sig is not optimal. Without building
> this a string and using eval, is there anything that can be done about this?
>

I don't think you can easily change the function's own definition,
other than by using eval (or equivalent shenanigans, like crafting
your own bytecode); but as of Python 3.something, the help() function
looks for a __wrapped__ attribute and will take function args from
that instead of the function itself. That way, when you use
functools.wraps(), it copies in the docstring and stuff, and as far as
help() is concerned, copies in the argument list too.

No idea whether you'll be able to do that too, but it's a fairly
effective way to get around the problem if you can.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web