spell method chaining?

Michael Hudson mwh at python.net
Fri Jun 8 13:45:44 EDT 2001


scarblac at pino.selwerd.nl (Remco Gerlich) writes:

> Usually you know that the base class is called eg Klass, and you simply call
> that. In this case I think you have to store it inside the class manually,
> like this:
> 
> def gen(B):
>    class W(B):
>       def __init__(self):
>          self.__base.__init__(self)
>    W._W__base = B
>    return W
> 
> (not the automatic 'name munging' the self.__base does, this way the
> attribute is somewhat protected from classes inheriting it)

But that doesn't work with 

/>> class C:
|..  def __init__(self):
|..   pass
\__ 
->> gen(gen(C))()

I couldn't think of a reasonable way around this in a few minutes of
thinking; I could come up with some unreasonable ones (like,
eg. bytecodehacks).

> This is a bit of a hack, but then what you're doing isn't all that
> common and it's fixed with nested scopes anyway.

Yes.

Cheers,
M.

-- 
  C is not clean -- the language has _many_ gotchas and traps, and
  although its semantics are _simple_ in some sense, it is not any
  cleaner than the assembly-language design it is based on.
                                        -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list