This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients Mark.Shannon, brett.cannon, gvanrossum, petr.viktorin, rhettinger, serhiy.storchaka, vstinner, yselivanov
Date 2021-02-19.18:01:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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


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:23gvanrossumsetrecipients: + gvanrossum, brett.cannon, rhettinger, vstinner, petr.viktorin, Mark.Shannon, serhiy.storchaka, yselivanov
2021-02-19 18:01:23gvanrossumsetmessageid: <>
2021-02-19 18:01:23gvanrossumlinkissue42990 messages
2021-02-19 18:01:23gvanrossumcreate