
On 2021-05-27 at 22:33:25 +1000, Steven D'Aprano steve@pearwood.info wrote:
Aside from globals, which we agree are Considered Harmful, you've suggested two alternative implementations:
something with closures;
hidden state in an object with a `__call__` method.
Closures are cool, but the hidden state really is inaccessible from outside the function. (At least I've never worked out how to get to it.) So the callable object is better for introspection and debugging.
Then fix your debugger. ;-)
As I recall, you're a proponent of fixing what's broken rather than creating workarounds.
(I also recall many discussions regarding failed sandboxes because of Python's nearly infinite capacity for introspection. Maybe closures are the path to a true sandbox.)
Globals, persistent locals, closures, statics, class variables, instance variables, etc. are all just different ways to hide state. IMO, we don't need another one.