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-20.01:03:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1613782992.74.0.850723350199.issue42990@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-02-20 01:03:12gvanrossumsetrecipients: + gvanrossum, brett.cannon, rhettinger, vstinner, petr.viktorin, Mark.Shannon, serhiy.storchaka, yselivanov
2021-02-20 01:03:12gvanrossumsetmessageid: <1613782992.74.0.850723350199.issue42990@roundup.psfhosted.org>
2021-02-20 01:03:12gvanrossumlinkissue42990 messages
2021-02-20 01:03:12gvanrossumcreate