new.instancemethod - how to port to Python3

Helmut Jarausch jarausch at skynet.be
Sun Apr 7 05:50:35 EDT 2013


Hi,

I'm trying to port a class to Python3.3 which contains

class  Foo :
    ....
    def to_binary(self, *varargs, **keys):
       ....

    ....
    self.to_binary = new.instancemethod(to_binary, self, self.__class__) 

    # Finally call it manually
    return apply(self.to_binary, varargs, keys)

----

The last line has been transformed to 
    return self.to_binary(*varargs, **keys)

by  2to3

But how to transform the line with new.instancemethod.
I've seen examples where
new.instancemethod(to_binary, ....)
is replaced by  to_binay
but this doesn't work here since to_binary isn't known.

If I simply delete it, I get an infinite recursion.

So, what's a working transcript of this code?

Many thanks for a hint,
Helmut.

P.S.  Is there collection of examples of necessary transformations to
Python3 which are not managed by 2to3 ?



More information about the Python-list mailing list