The issue here is it sounds like you want to use globals, without using the
As far as I'm concerned a global is a global - no matter what you call it.
So don't trick yourself here, rather then identifying globals as bad, just accept there are times when a state is global and try to do it in the least error-prone way.
Of course try avoid these situations - but lets just assume you checked the alternatives and came to the conclusion some global state is needed.
Rather then mixing global state in with existing classes, I prefer to explicitly define a class which stores state, especially if its shared between multiple functions/classes.
# Singleton for storing global state
__slots__ = (
self.uploading = False
self.token_reload = True
self.size_text = ""
# One state to rule them all (otherwise known as a singleton)
my_state = _MyState()
The advantage with using
__slots__ is you clearly define whats global, and you cant accidentally assign some invalid var.
.size_tetx = "" - will raise an error, with very large scripts allowing such mistakes to fail silently can loose your time debugging silly typos.
Heres an example of such a class used in the Sketchfab addon