Guido van Rossum <gu...@python.org> added the comment:
Thanks, that's clearer. I'm still worried about the change in semantics where globals["__builtins__"] is assigned a different dict after the function object has been created (similar to https://bugs.python.org/file49816/func_builtins2.py). I.e. def foo(): return len("abc") code = foo.__code__ g = {"__builtins__": {"len": len}} f = FunctionType(code, g) f() # Succeeds g["__builtins__"] = {} f() # Fails in 3.9 and before, passes in 3.10 Assuming code uses len, does f() succeed or fail? I realize this is a pretty esoteric, but it does show the change in semantics (from later to earlier binding). Should we care? I like early binding because it allows more optimizations[1], but traditionally Python's semantics use late binding. [1] Not in this case, the user could still change the meaning of len() with e.g. g["__builtins__"]["len"] = lambda x: return 42 ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42990> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com