Bugs item #1115039, was opened at 2005-02-02 15:59 Message generated for change (Comment added) made by rhettinger You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1115039&group_id=5470
Category: Parser/Compiler Group: Python 2.3 >Status: Closed >Resolution: Invalid Priority: 5 Submitted By: Andrew Collier (carou) Assigned to: Nobody/Anonymous (nobody) Summary: eval != literal scope in nested function Initial Comment: python 2.3 as installed by default in MacOS X 10.3.7 This may be the same as item 991196, but that's my uneducated guess since I don't understand the cause of either one... (in fact it may not even really be a bug, but at the least this is behaviour I'm unable to explain). It seems that fewer symbols are available to eval() than are available to literal code. The best way to describe the problem is with the attached short example file. In the function evalfunction2(), a call via eval() is unable to resolve the symbol name evalfunction1 - even though it would be possible to call evalfunction1() directly. But if the code *does* call evalfunction1() directly, then the eval() can see that symbol too(!). ---------------------------------------------------------------------- >Comment By: Raymond Hettinger (rhettinger) Date: 2005-02-02 18:26 Message: Logged In: YES user_id=80475 Sorry, this isn't a bug. The eval() function is documented to only search globals() and local(). The nested scope of eval's caller is not included. In your code, callfunction2 works because callfunction1 can be found in the nested scope. In contrast, evalfunction2 fails because evalfunction1 is not in the locals() or globals(); instead, is in a enclosing nested scope which is not searched. The reason that evalfunction2 works if you uncomment the extra code is the subsequent reference to evalfunction1 gets it brought into locals() at compilation time (when the def is executed). For real code, is you want a nested scope object to be found by eval, then either reference it in the same function that calls eval() or, more explicitly, just add it to a dictionary of things that should be visible to eval(). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1115039&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com