Message387340
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 |
|
Date |
User |
Action |
Args |
2021-02-19 18:01:23 | gvanrossum | set | recipients:
+ gvanrossum, brett.cannon, rhettinger, vstinner, petr.viktorin, Mark.Shannon, serhiy.storchaka, yselivanov |
2021-02-19 18:01:23 | gvanrossum | set | messageid: <1613757683.36.0.638587405734.issue42990@roundup.psfhosted.org> |
2021-02-19 18:01:23 | gvanrossum | link | issue42990 messages |
2021-02-19 18:01:23 | gvanrossum | create | |
|