Josh Rosenberg added the comment:

This is what I get for leaving a response up and working on it intermittently 
for three hours, and not rechecking: I found the same basic problem.

For the record, I also found a terribly hacky way of doing this sort of 
rebinding manually, should you actually need to do so under the current design:

def make_class_closure(__class__):
    '''Makes a one-tuple closure with a cell for the provided class'''
    return (lambda: super).__closure__

class MyList(list):
    def insert(self, index, object):
        super().insert(index, object)

class MyList2(list):
    pass

MyList2.insert = types.FunctionType(MyList.insert.__code__, globals(), 
closure=make_class_closure(MyList2))

It would need further improvements to recognize when it needs to run, deal with 
existing closures, handle top-level functions without __class__ in their 
closure co_freevars, etc., and I won't even pretend that's a sane workaround 
for the problem, but it does demonstrate what is happening/what would need to 
be changed to make it work, if indeed that's desirable.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29944>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to