As stated in copy
documentation:
This module does not copy types like module, method, stack trace, stack frame, file, socket, window, array, or any similar types. It does “copy” functions and classes (shallow and deeply), by returning the original object unchanged
You can try to do it using metaclasses:
class Base(object):
foo = "bar"
# Create a new class called `base_copy` with attributes and base classes
# from Base without inheriting from Base
base_copy = type('base_copy', Base.__bases__, dict(Base.__dict__))
# Will delete attribute on `base_copy` class
del base_copy.foo
base_again = type('base_again', Base.__bases__, dict(Base.__dict__))
print(hasattr(base_again, 'foo')) # True
You can try using deepcopy
on dict(Base.__dict__)
object to copy objects like list
, dict
and others.