[Python-Dev] Adding a builtins parameter to eval(), exec() and import(). (original) (raw)

Mark Shannon mark at hotpy.org
Thu Mar 8 13:06:09 CET 2012


Jim J. Jewett wrote:

http://mail.python.org/pipermail/python-dev/2012-March/117395.html Brett Cannon posted: [in reply to Mark Shannon's suggestion of adding a builtins parameter to match locals and globals]

It's a mess right now to try to grab the import() implementation and this would actually help clarify import semantics by saying that import() for any chained imports comes from import()s locals, globals, or builtins arguments (in that order) or from the builtins module itself (i.e. tstate->builtins). How does that differ from today?

The idea is that you can change, presumable restrict, the builtins separately from the globals for an import.

If you're saying that the locals and (module-level) globals aren't always checked in order, then that is a semantic change. Probably a good change, but still a change -- and it can be made indepenently of Mark's suggestion. Also note that I would assume this was for sandboxing,

Actually, I just think it's a cleaner implementation, but sandboxing is a good excuse :)

and that missing names should not fall back to the "real" globals, although I would understand if bootstrapping required the import statement to get special treatment.

(Note that I like Mark's proposed change; I just don't see how it cleans up import.)

I don't think it cleans up import, but I'll defer to Brett on that. I've included import() along with exec and eval as it is a place where new namespaces can be introduced into an execution. There may be others I haven't though of.

Cheers, Mark.



More information about the Python-Dev mailing list