Adding state.get_state and then calling it at the top of each module that needs access to the state is a really bad idea I think? Even though it reduces a lot of state = get_state() calls inside functions, this sort of top-level instantiation of global objects just irks me, and it has proven to be a very painful when testing due to the tests mutating the State object.
I'm having a hard time wrapping my head around the problem completely, but it seems like even when using State as a singleton, the modules that have already instantiated State via get_state() could conceivably have a different version of the State object due to the shenanigans we do when resetting the state in tests. Maybe we should just do state = get_state() where it is required?
This is a really poorly explained issue for now... 4 hours of fixing broken tests due to mutation of global objects has fried my brain.
Adding
state.get_stateand then calling it at the top of each module that needs access to the state is a really bad idea I think? Even though it reduces a lot ofstate = get_state()calls inside functions, this sort of top-level instantiation of global objects just irks me, and it has proven to be a very painful when testing due to the tests mutating theStateobject.I'm having a hard time wrapping my head around the problem completely, but it seems like even when using
Stateas a singleton, the modules that have already instantiatedStateviaget_state()could conceivably have a different version of theStateobject due to the shenanigans we do when resetting the state in tests. Maybe we should just dostate = get_state()where it is required?This is a really poorly explained issue for now... 4 hours of fixing broken tests due to mutation of global objects has fried my brain.