spell method chaining?

Robin Becker robin at jessikat.fsnet.co.uk
Fri Jun 8 20:43:47 CEST 2001


In article <3B2111FF.D998EEE4 at letterror.com>, Just van Rossum
<just at letterror.com> writes
....
>s inheriting it)
>
>You can avoid that by spelling it like this:
>
>def gen(B):
>   class W(B):
>      __base = B
>      def __init__(self):
>         self.__base.__init__(self)
>   return W
>
>Just
this nearly works fine in 2.1 if I have a from __future__ import
nested_scopes, but gives a shadowed variable warning if not. In any case

from __future__ import nested_scopes
def gen(B):
        class W(B):
                __base = B
                def __init__(self):
                        self.__base.__init__(self)
        return W

class C:
        def __init__(self):
                pass

gen(gen(C))()

recurs infinitely. In 2.1 with nested scopes my original formulation is
OK,
 

from __future__ import nested_scopes
def gen(B):
        class W(B):
                def __init__(self):
                        B.__init__(self)
        return W

class C:
        def __init__(self):
                pass

gen(gen(C))()

but the following gives a compile error for some reason.

from __future__ import nested_scopes
def gen(B):
        class W(B):
                __base=B
                def __init__(self):
                        B.__init__(self)
        return W

class C:
        def __init__(self):
                pass

from __future__ import nested_scopes
def gen(B):
        class W(B):
                __base=B
                def __init__(self):
                        B.__init__(self)
        return W


Fatal Python error: non-string found in code slot

abnormal program termination


-- 
Robin Becker



More information about the Python-list mailing list