Message290858
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. |
|
Date |
User |
Action |
Args |
2017-03-30 16:13:17 | josh.r | set | recipients:
+ josh.r, ncoghlan, xiang.zhang, bup |
2017-03-30 16:13:17 | josh.r | set | messageid: <1490890397.35.0.390640064802.issue29944@psf.upfronthosting.co.za> |
2017-03-30 16:13:17 | josh.r | link | issue29944 messages |
2017-03-30 16:13:17 | josh.r | create | |
|