Consider this example:
def foo():
raise BaseException()
globals()["bar"] = foo
foo.__name__ = "bar"
# foo.__code__.co_name = "bar" # - Error: property is readonly
bar()
The output is:
Traceback (most recent call last):
File "*path*/kar.py", line 9, in <module>
bar()
File "*path*/kar.py", line 2, in foo
raise BaseException()
BaseException
How can I change the function name "foo" in the traceback? I already tried foo.__name__ = "bar", globals()["bar"] = foo and foo.__code__.co_name = "bar", but while the first two one just do nothing, the third one fails with AttributeError: readonly attribute.

