Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#9 eval() doesn't work

closed-fixed
Armin Rigo
5
2002-08-28
2002-08-24
Neal Norwitz
No

This program:

g = 5
def t(): print eval('g')
t()

doesn't work with pysco (get a NameError), but works
fine without psyco.

Redhat Linux 7.2, Python 2.1.1

Discussion

  • Armin Rigo
    Armin Rigo
    2002-08-25

    • assigned_to: nobody --> arigo
     
  • Armin Rigo
    Armin Rigo
    2002-08-25

    Logged In: YES
    user_id=4771

    Similar problems are found with globals(), execfile(), and
    possibly a couple of other functions which use information
    about the last frame (here its 'globals' dictionary). I
    cannot fix the functions without changing the interpreter
    source, but I can plug my own Psyco-aware functions into the
    __builtins__ when Psyco loads, as I did with
    sys._getframe().

     
  • Armin Rigo
    Armin Rigo
    2002-08-26

    • status: open --> open-fixed
     
  • Armin Rigo
    Armin Rigo
    2002-08-26

    Logged In: YES
    user_id=4771

    Should be fixed in CVS. If you can, please check it.

    The problem appears on any function that implicitely grabs
    the callers' globals and/or locals. I fixed the following
    ones: eval(), execfile(), globals(), locals(), vars(),
    dir(), input().

     
  • Neal Norwitz
    Neal Norwitz
    2002-08-28

    Logged In: YES
    user_id=33168

    The example in this bug report is fixed. I also tested
    simple tests w/exec, globals, locals, and vars.

    However, I pulled the example from the pychecker tests.
    I'm still getting most of the NameErrors in pychecker. I
    also got a
    core dump for at least one test -- 49.

    If you want to use pychecker, download from pychecker.sf.net.
    Modify pychecker/warn.py (add to the end of the file):
    import psyco
    psyco.bind(_checkCode)

    Then run the tests: ./test_check.sh

     
  • Armin Rigo
    Armin Rigo
    2002-08-28

    Logged In: YES
    user_id=4771

    Thanks for the core dump bug; just fixed one more subtle
    case in dispatcher.c... The NameErrors all code from the
    following line in CodeChecks.py:941:

    eval("codeSource.module.module.%s.__name__" % operand)

    because 'codeSource' is a local variable. This could anyway
    be considered as bad Python style; it works fine if the above
    expression is replaced by its getattr() version.

     
  • Armin Rigo
    Armin Rigo
    2002-08-28

    • status: open-fixed --> closed-fixed
     
  • Neal Norwitz
    Neal Norwitz
    2002-08-28

    Logged In: YES
    user_id=33168

    Agree about the abuse of eval. Works fine with getattr.