Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102503
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Random832 <random832@fastmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Efficient Wrappers for Instance Methods |
| Date | Thu, 04 Feb 2016 13:35:32 -0500 |
| Lines | 32 |
| Message-ID | <mailman.69.1454610940.30993.python-list@python.org> (permalink) |
| References | <56B263C1.7030309@mail.de> <CAERt=-zJKowMvTmFD9p_kyxDBKsvgA48P0sMNUr9aKHOSSVt9Q@mail.gmail.com> <56B26940.3090609@mail.de> <CAERt=-wf1+WA462erbYTM=74Sx+8-gOjcC5dY-d0Ma2B56AidQ@mail.gmail.com> <56B26D3D.6040703@mail.de> <n8tqt8$8m8$1@ger.gmane.org> <56B2747B.6050209@mail.de> <1454543258.197018.511336178.74125AA7@webmail.messagingengine.com> <56B379CD.5090903@mail.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de fUZcllfdw7WJdaZ0F18a6AKdIhamp5vu71Vb3FpFtT0g== |
| Return-Path | <random832@fastmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'none:': 0.05; '(of': 0.07; 'dynamically': 0.07; 'inherited': 0.09; 'received:internal': 0.09; '{})': 0.09; 'wed,': 0.15; 'thu,': 0.15; 'cls': 0.16; 'heap': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:10.202.2.44': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:compute4.internal': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'case.': 0.18; 'work,': 0.21; 'to:2**1': 0.21; 'meant': 0.22; 'mind.': 0.22; 'feb': 0.23; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'idea': 0.28; 'creating': 0.30; 'checks': 0.30; 'class.': 0.30; 'class': 0.33; 'instances': 0.33; "i'll": 0.33; 'changing': 0.34; 'replace': 0.35; 'something': 0.35; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'two': 0.37; 'method': 0.37; 'received:66': 0.38; 'to:addr:python.org': 0.40; 'your': 0.60; "you'll": 0.61; 'header:Message-Id:1': 0.61; 'six': 0.65; 'boxes.': 0.84; 't),': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=ISH6jj2M1n2gWGwKn5noKBTUGNo=; b=VwzQJd REBqKdliwGSpFc77f9hLrKyqZOqLfJ+via1TzOHgS88N2jUCmVKYuDy/eYJAJ/ed oiFWbpTD2reu3kZXIyyIQjd+rSVFpfZ/6eplilG7JBtZPN5/cvYlr9xiP0kgTTlu MBgW2Qf/BOFr0ipRyZtm875BylbxUDOK8LNLc= |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=ISH6jj2M1n2gWGw Kn5noKBTUGNo=; b=KyEPqwxcE8Wo79kPPdfJmsTeahil28BSZYlTN1AtZMUr9yd tLnVOXvyljvV+7NWwtDMFc0PgOzewUNThCD7KYLTQH/rFWP7K2I4bJjT7SHmGyBh uvx1FW2pzuYlPoohOrpMnCGvrT4NovYS1abulS7YbI3R+EXD/6Dao7Fkm4H0= |
| X-Sasl-Enc | C4KU4TOjA/fG+klz7OsGAvbqjNio/hs6bOuDad6v9TU4 1454610932 |
| X-Mailer | MessagingEngine.com Webmail Interface - ajax-9c016a65 |
| In-Reply-To | <56B379CD.5090903@mail.de> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21rc1 |
| 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> |
| Xref | csiph.com comp.lang.python:102503 |
Show key headers only | View raw
On Thu, Feb 4, 2016, at 11:18, Sven R. Kunze wrote:
> On 04.02.2016 00:47, Random832 wrote:
> > On Wed, Feb 3, 2016, at 16:43, Sven R. Kunze wrote:
> >> Actually a nice idea if there were no overhead of creating methods for
> >> all heap instances separately. I'll keep that in mind. :)
> > What about changing the class of the object to one which is inherited
> > from its original class and has the method you want? What about reaching
> > into the class and changing the method in the first place? Either may
> > not be appropriate, of course, depending on your use case.
>
> There is no base class.
I meant something like...
Class C:
replace = heapreplace
Cs = {}
...
if not isinstance(x, C)
T = type(x)
cls = cache.get(T)
if cls is None:
cls = type('C_'+T.__name__, (C, T), {})
x.__class__ = cls
(Of course, by dynamically reassigning __class__ and using the type
constructor, this checks two of the three "crazy type system voodoo"
boxes. I have no idea if it will work, or if I've made a mistake, or if
you'll be able to understand it in six months.)
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Efficient Wrappers for Instance Methods Random832 <random832@fastmail.com> - 2016-02-04 13:35 -0500
csiph-web