After deleting a builtin function like this, I want to restore it without restarting the interpreter.
>>> import builtins
>>> del builtins.eval
>>> builtins.eval = None
I tried reloading the builtin module using importlib
, that didn't restore eval.
>>> import importlib
>>> importlib.reload(builtins)
<module 'builtins' (built-in)>
>>> eval("5 + 5")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
I also tried to assign a __builtins__
variable from another module. That didn't work as well.
>>> import os
>>> __builtins__ = os.__builtins__
>>> eval()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
Is there a way to restore a builtin function after deleting it?