[IronPython] Issues with "exec X in Y"

Jonathan Jacobs korpse-ironpython at kaydash.za.net
Sat Jul 23 15:30:49 CEST 2005


Me again,

I ran across a couple of issues using the above syntax. I usually use it 
when making use of "config" files which are just Python source files:
   config = {}
   exec file('config.py') in config
   del config['__builtins__']

1.) Specifying locals or globals broke things. As far as I can tell this 
is because the CodeGen.emitCall call (called from ExecStmt.Emit) was 
being asked to find a method that took two objects of type "object", 
instead of two objects of type "object" and type "IDictionary<object, 
object>", respectively, of which there are none.

2.) The "exec" statement didn't deal with file objects at all.

I'm not sure whether anybody is aware of these, so I'm not sure if 
they've already been taken care of. I've attached a patch to address 
these issues. My patch however doesn't add a "__builtins__" key to the 
mappable types, so the above code would actually error out in IronPython 
with my patch, so someone probably wants to add that.

In order to make my life easier, I also implemented the "name" property 
on file objects.

Hopefully this helps someone.

--
Jonathan
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: exec-in.patch
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20050723/864e22a9/attachment.ksh>


More information about the Ironpython-users mailing list