CSSE1001 / MyPyTutor

Interactive tutorial application for Python3.
Other
7 stars 12 forks source link

redirect_input_prompt causes infinite recursion #68

Closed sapi closed 9 years ago

sapi commented 9 years ago

Attempting to redirect the input prompt causes a RuntimeError (recursion depth exceeded).

Steps to reproduce:

Steps to fix/hide:

This is reproducible in 0065c9c6596ba9a24e9be8f66feaaaa2713d0d6c, the last commit before I merged the ui branch, so it's not that.

@jgat You may be interested in this one.

(Incidentally, you can assume that lcls is always a globals dict. It needs to be; exec fails spectacularly if given separate dicts. I agree the naming is stupid; I forgot to update it when I fixed the exec bugs, but will try to do so soon.)

sapi commented 9 years ago

That one took a bit to track down. I'd be curious about why (if?) it worked on your system, and if so, what the difference between our configurations is.

Certainly on any sane system this should be the expected output:

In [1]: import builtins

In [2]: builtins is globals()['__builtins__']
Out[2]: True

But it certainly didn't click for me until I stared at the traceback for a little while.

sapi commented 9 years ago

Oh, and probably worth mentioning here just so it's documented somewhere (I forgot to put it in a comment) -- I changed redirect_input_prompt to require either gbls['input'] or gbls['__builtins__'].

As we're using a globals dict returned from exec, the latter is actually guaranteed.

sapi commented 9 years ago

Found the cause.

I run scripts from the shell (ipython) to get nicer tracebacks. Something about that triggers the builtins optimisation; I can't reproduce it when running MyPyTutor.py with python directly.

Oh well. It's probably a good thing to have fixed anyway.