Message387306
Updated PR documentation:
---
The types.FunctionType constructor now inherits the current builtins
if the globals parameter is used and the globals dictionary has no
"__builtins__" key, rather than rather than using {"None": None} as
builtins: same behavior than 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.
---
This PR makes FunctionType makes more consistent with other Python functions.
Also, it doesn't prevent people to attempt building a "sandbox", it remains possible to override __builtins__ in FunctionType, eval(), exec(), etc.
Usally, such sandbox pass a modified builtins namespace to eval() and exec() and the functions simply inherit it, functions defines with "def function(...): ..." and functions created with types.FunctionType constructor: my PR only impacts a very specific case, when types.FunctionType is called with a different globals dictionary which has no "__builtins__" key. |
|
| Date |
User |
Action |
Args |
| 2021-02-19 11:29:58 | vstinner | set | recipients:
+ vstinner, gvanrossum, brett.cannon, rhettinger, petr.viktorin, Mark.Shannon, serhiy.storchaka, yselivanov |
| 2021-02-19 11:29:58 | vstinner | set | messageid: <[email protected]> |
| 2021-02-19 11:29:58 | vstinner | link | issue42990 messages |
| 2021-02-19 11:29:57 | vstinner | create | |
|