After much searching, the only way I have found to solve my particular problem is to use dynamic inheritance. It is easy enough following the guide from here and a few other SO questions; most table is this.
Using a modified version of the contrived example from the first link:
def makeinst(cls, *args, **kwargs):
class NewClass(cls): pass
return NewClass(*args, **kwargs)
mylist = makeinst(list,(1,2))
This works as I would hope but it can't be pickled:
pickle.dumps(mylist)
...
AttributeError: Can't pickle local object 'makeinst.<locals>.NewClass'
I understand why this doesn't work but what I want to know is there a way around it? Is there a better way to dynamically subclass something?
(FWIW, dill
can't do it either. See dill issue #56)