Guido van Rossum <gu...@python.org> added the comment:
Thanks for the clarifications, Victor! So I now understand: the *identity* of the builtins dict used by a function's code is captured when the function object is created. And I understand why: it's so that in the fast path for the LOAD_GLOBAL opcode we won't have to do a dict lookup in globals to find the builtins. Regarding the text in What's New 3.10 about this at https://docs.python.org/dev/whatsnew/3.10.html#other-language-changes, I recommend adding there that func.__builtins__ is initialized from globals["__builtins__"], if it exists, else from the frame's builtins, when the function object is created; like you state in https://github.com/python/cpython/pull/24564. Or perhaps make one of these paragraphs refer to the other for details, since they are duplicate mentions of the same behavior change (once the latter PR lands). Also, thanks to you and Mark and everyone else who has worked on optimizations like the globals cache and the method cache. ---------- _______________________________________ 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