[Python-Dev] Adding a builtins parameter to eval(), exec() and import(). (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Fri Mar 9 12:03:54 CET 2012
- Previous message: [Python-Dev] Adding a builtins parameter to eval(), exec() and __import__().
- Next message: [Python-Dev] Adding a builtins parameter to eval(), exec() and __import__().
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Mar 9, 2012 at 6:19 PM, Mark Shannon <mark at hotpy.org> wrote:
The Python API would be changed, but in a backwards compatible way. exec, eval and import would all gain an optional (keyword-only?) "builtins" parameter.
No, some APIs effectively define protocols. For such APIs, adding parameters is almost of comparable import to taking them away, because they require that other APIs modelled on the prototype also change. In this case, not only exec() has to change, but eval, import, probably runpy, function creation, eventually any third party APIs for code execution, etc, etc.
Adding a new parameter to exec is a change with serious implications, and utterly unnecessary, since the API part is already covered by setting builtins in the passed in globals namespace (which is appropriately awkward to advise people that they're doing something strange with potentially unintended consequences or surprising limitations).
That said, binding a reference to the builtin early (for example, at function definition time or when a new invocation of the eval loop first fires up) may be a reasonable idea, but you don't have to change the user facing API to explore that option - it works just as well with "builtins" as an optional value in the existing global namespace.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] Adding a builtins parameter to eval(), exec() and __import__().
- Next message: [Python-Dev] Adding a builtins parameter to eval(), exec() and __import__().
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]