Why can you change globals().__getitem__ but not __setitem__?

Support for LOAD_GLOBAL calling __getitem__ looks like it was added in Python 3.3. The motivation was reduced memory usage and improved speed by sharing dictionary keys. I don’t seen any discussion of global variables or __getitem__ on non-dictionaries, so I suspect that change was incidental.

1 Like