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


Groups > comp.lang.python > #102505

Re: Efficient Wrappers for Instance Methods

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From "Sven R. Kunze" <srkunze@mail.de>
Newsgroups comp.lang.python
Subject Re: Efficient Wrappers for Instance Methods
Date Thu, 4 Feb 2016 21:14:27 +0100
Lines 36
Message-ID <mailman.71.1454617395.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> <1454610932.523536.512150754.7911A33B@webmail.messagingengine.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de PjxW+zqzCECKZ+wUVth0hQn92+dxeaqxw2H8up9OuaZQ==
Return-Path <srkunze@mail.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'none:': 0.05; '(of': 0.07; 'dynamically': 0.07; 'inherited': 0.09; '{})': 0.09; 'wed,': 0.15; 'thu,': 0.15; 'cls': 0.16; 'heap': 0.16; 'nightmare.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'case.': 0.18; '>>>': 0.20; '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; 'header:User-Agent:1': 0.26; '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; 'received:10.0': 0.34; 'best,': 0.35; '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; 'agree': 0.37; 'method': 0.37; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; "you'll": 0.61; 'charset:windows-1252': 0.62; 'six': 0.65; 'boxes.': 0.84; 't),': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mail201212; t=1454616870; bh=ignqNBUUP2B2yTck/kb52QQG5GVrah0ZRjd5S0Sh8jg=; h=Subject:To:References:From:Date:In-Reply-To:From; b=TKxNaBox+PF4zM4/xGTaOUxcdHAtAEaGK2DFoTU2VYKOY3ZRlGRL5BFwiItxfxdjq pJpTaXrL76dPQXCaeeQgRDyvZnz/yZEy3dvZWdca6jc3bvpUZLNIAkwt2zohm64r1n RNou5wKFNndmpODonQocNxMvs9gFYr9mpHh6JUbs=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1
In-Reply-To <1454610932.523536.512150754.7911A33B@webmail.messagingengine.com>
X-purgate clean
X-purgate This mail is considered clean (visit http://www.eleven.de for further information)
X-purgate-type clean
X-purgate-Ad Categorized by eleven eXpurgate (R) http://www.eleven.de
X-purgate This mail is considered clean (visit http://www.eleven.de for further information)
X-purgate clean
X-purgate-size 1292
X-purgate-ID 154282::1454616870-000009F3-F6EC81E5/0/0
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:102505

Show key headers only | View raw


On 04.02.2016 19:35, Random832 wrote:
> 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.)

I think I agree with you that this might be a maintenance nightmare. ;)

Best,
Sven

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


Thread

Re: Efficient Wrappers for Instance Methods "Sven R. Kunze" <srkunze@mail.de> - 2016-02-04 21:14 +0100

csiph-web