This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients bup, josh.r, ncoghlan, xiang.zhang
Date 2017-03-30.16:13:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1490890397.35.0.390640064802.issue29944@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-03-30 16:13:17josh.rsetrecipients: + josh.r, ncoghlan, xiang.zhang, bup
2017-03-30 16:13:17josh.rsetmessageid: <1490890397.35.0.390640064802.issue29944@psf.upfronthosting.co.za>
2017-03-30 16:13:17josh.rlinkissue29944 messages
2017-03-30 16:13:17josh.rcreate