I found this issue in the thread: https://bugs.python.org/issue18195
>>> from copy import deepcopy
>>> import types
>>> origin_types = deepcopy(types)
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'update'
If I really want to deepcopy
a module, what to do?
Also, it must has some reason for team who did not implement this feature. Hope someone can explain the risk of doing this.
[Updated] Here is my purpose
import os
from copy import deepcopy
from importlib import reload
def disabled_func(f):
def inner(*args, **kwargs):
return f(*args, **kwargs)
return inner
class OSModuleCustomizer(object):
def disable_method(self, os_method):
setattr(os, os_method, disabled_func)
def save_customized_module(self):
self.custom_module = deepcopy(os)
def get_customized_module(self):
return self.custom_module
#original function
os.system("ls") # works
#modifying module
omc = OSModuleCustomizer()
omc.disable_method("system")
os.system("ls") # empty
#saving customized module
omc.save_customized_module();
#reload
reload(__import__("os"))
os.system("ls") # works
#reload saved customized-module
os = omc.get_customized_module()
os.system("ls") # empty