]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-42990: Functions inherit current builtins (GH-24564)
authorVictor Stinner <vstinner@python.org>
Sat, 20 Feb 2021 14:17:18 +0000 (15:17 +0100)
committerGitHub <noreply@github.com>
Sat, 20 Feb 2021 14:17:18 +0000 (15:17 +0100)
commit46496f9d12582bf11f4911ad0f23315d6f277907
tree8382b24a5036df07fe75c59f0a45cd401d84b17a
parent4233ff3ee4add287b3617f38943d01a7a6f4d7c4
bpo-42990: Functions inherit current builtins (GH-24564)

The types.FunctionType constructor now inherits the current builtins
if the globals dictionary has no "__builtins__" key, rather than
using {"None": None} as builtins: same behavior as eval() and exec()
functions.

Defining a function with "def function(...): ..." in Python is not
affected, globals cannot be overriden with this syntax: it also
inherits the current builtins.

PyFrame_New(), PyEval_EvalCode(), PyEval_EvalCodeEx(),
PyFunction_New() and PyFunction_NewWithQualName() now inherits the
current builtins namespace if the globals dictionary has no
"__builtins__" key.

* Add _PyEval_GetBuiltins() function.
* _PyEval_BuiltinsFromGlobals() now uses _PyEval_GetBuiltins() if
  builtins cannot be found in globals.
* Add tstate parameter to _PyEval_BuiltinsFromGlobals().
Doc/whatsnew/3.10.rst
Include/internal/pycore_ceval.h
Lib/test/test_funcattrs.py
Misc/NEWS.d/next/Core and Builtins/2021-02-18-15-12-30.bpo-42990.toAqBH.rst [new file with mode: 0644]
Objects/frameobject.c
Objects/funcobject.c
Python/ceval.c