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


Groups > comp.lang.python > #97093

Re: Modifying signature of ctor in class

Path csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'args': 0.04; 'modify': 0.04; 'constructor': 0.07; 'dynamically': 0.07; 'cc:addr:python- list': 0.09; 'definition,': 0.09; 'python': 0.10; 'itself.': 0.11; 'argument': 0.15; 'docstring': 0.16; 'eval': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'stuff,': 0.16; 'subject:class': 0.16; 'wrote:': 0.16; 'string': 0.17; 'attribute': 0.18; 'input': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fairly': 0.22; 'accommodate': 0.22; 'doc': 0.22; 'fine,': 0.22; 'sep': 0.22; 'am,': 0.23; '(or': 0.23; 'header:In-Reply-To:1': 0.24; 'equivalent': 0.27; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'idea': 0.28; 'looks': 0.29; 'strings,': 0.29; 'too.': 0.30; 'class': 0.33; 'problem': 0.33; 'this?': 0.34; 'add': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'but': 0.36; 'instead': 0.36; 'there': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'signature': 0.37; 'anything': 0.38; 'building': 0.38; 'easily': 0.39; 'where': 0.40; 'your': 0.60; "you'll": 0.61; 'effective': 0.63; 'chrisa': 0.84; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=bFCyo9pR2G2KfRC5Doe9Ftulq+ewUiqffW8EyKFq5F4=; b=JeuRAxq9p9jk6fO/7dM8eKFrY5cp/oFcwVRLuitjr937cuAMd9tiA3I2y9QueHsaZO HzjB+w73Hy1gswMHBRWU/sE8kF6wDvdyI/j7iGgvtv0mnwyg7v2Sf+mULDOt5LXZWneN nNy0b4oObwVfJ/5gL6X5iFzMg7cl2kh3kZiBms6y1Et/AWNAZbL57SHHCLiI/MJzSsix OW3Vfq5sFXv3+A5VlDKc9XewWWznp7rfuZLlXqyNnhQSSrkMXmddl4qNTGZUDBM1mR4j 7eSuFyN06C5ri+ChT4Iyd/t38uME7jL0FvksMb59LcKfiaPyoNWQElGycLp9x80a6XUE gJIw==
MIME-Version 1.0
X-Received by 10.107.162.196 with SMTP id l187mr2867818ioe.19.1443130738558; Thu, 24 Sep 2015 14:38:58 -0700 (PDT)
In-Reply-To <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com>
References <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com>
Date Fri, 25 Sep 2015 07:38:58 +1000
Subject Re: Modifying signature of ctor in class
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.145.1443130747.28679.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1443130747 news.xs4all.nl 23765 [2001:888:2000:d::a6]:58332
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:97093

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web