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


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

Re: Efficient Wrappers for Instance Methods

Started by"Sven R. Kunze" <srkunze@mail.de>
First post2016-02-04 21:14 +0100
Last post2016-02-04 21:14 +0100
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: Efficient Wrappers for Instance Methods "Sven R. Kunze" <srkunze@mail.de> - 2016-02-04 21:14 +0100

#102505 — Re: Efficient Wrappers for Instance Methods

From"Sven R. Kunze" <srkunze@mail.de>
Date2016-02-04 21:14 +0100
SubjectRe: Efficient Wrappers for Instance Methods
Message-ID<mailman.71.1454617395.30993.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web