There are 3 modules: m1.py
, m2.py
and main.py
. We can only
change the code of main.py
and inside it we want to call a function
from m1
: m1.m1()
. However, hidden deep inside the spaghetti codebase
m1
is calling m2.m2()
on the top level, so it gets executed every
time we import m1
. And we don't want that
How can we import m1
without m2.m2()
getting executed and without altering
any code inside m1.py
and m2.py
?
We mutate the m2
module inside main
before m1
is imported.