Modifying locals()
doesn't work reliably, even in CPython. It happens to work in module and class scopes, but it fails inside a function (any modifications "won't take", since locals()
provides a copy of the local namespace in that case, rather than a reference to the real thing)
However, globals()
is different, since that always refers to the module namespace, and module namespaces are required to behave like ordinary dictionaries. So yes, the lack of a warning on globals()
isn't an oversight, it really is allowed.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…