python / cpython

The Python programming language
https://www.python.org
Other
63.65k stars 30.49k forks source link

DOC: func.__builtins__ was exposed in 3.10 but not documented #101888

Open mattip opened 1 year ago

mattip commented 1 year ago

Documentation

In solving issue 42990 the func_builtins field of PyFunctionObject, added in 3.9, was exposed to python as func.__builtins__ and this was documented in the release notes for 3.10:

Functions have a new __builtins__ attribute which is used to look for builtin symbols when a function is executed, instead of looking into __globals__['__builtins__']. The attribute is initialized from __globals__["__builtins__"] if it exists, else from the current builtins. (Contributed by Mark Shannon in bpo-42990.), the actual PR is #24559 by @vstinner.

The added attribute is not documented in the "User-defined functions" table of attributes in the data model (that page could use some internal structure so I could link to an anchor). I think it should be if it is part of the language model, or is this a CPython implementation detail? From the discussion in the issue, it seems the former is true: it is part of the language model.

mattip commented 1 year ago

@vstinner, @markshannon any thoughts? Should PyPy implement this even though on PyPy __builtins__ always references the module and never a dictionary?