I currently have code like this:
cache = 1
def foo():
global cache
# many
# lines
# of code
cache = 2
However, this may lead to hard-to-find-bugs in the future, because the reader may not notice that global cache
appears somewhere above cache = 2
. Alternatively, a contributor may mistakenly add def bar(): cache = 2
and forget to add the global cache
.
How can I avoid this pitfall?