TypeError: __class__ assignment only supported for heap types or ModuleType subclasses
问题 I'm trying to copy functions from an arbitrary 'base' class into my new object. However, I'm getting the following error with this sample code. class my_base: def print_hey(): print("HEY") def get_one(): print(1) class my_ext: def __init__(self, base): methods = [method for method in dir(base) if callable(getattr(base, method))] for method in methods: setattr(self, method, getattr(base, method)) me = my_ext(my_base) me.get_one() The above gets this error on the call to setattr . TypeError: _