IDLE's PyShell

Tim Peters tim_one at email.msn.com
Thu Jul 22 03:07:48 EDT 1999


[Vladimir Marangozov]
> ...
> Actually, I really don't understand very well how the PyShell works.

Then you understand it a lot better than I do <0.7 wink>.

> Here's another little exercise that causes some weird behavior. If you can
> reproduce it, then it's most probably a bug unrelated to my
> personal install.
>
> 1) start a brand new idle.py (the PyShell welcomes you to Pythonland)
> 2) press RETURN a couple of times (just to warm the linecache ;-)
> 3) See the contents of the cache dict by typing "PyShell.linecache.cache"
> 4) Now provoke a name error by typing, say, "bonk"
>
> we get the usual Traceback ... NameError: bonk.
> Everything seems to be perfect, until...
>
> 5) See again the contents of the cache with PyShell.linecache.cache
>
> I get a huge output, containing the entire PyShell.py source...

Yes, that happens for me too.

> With all due respect to PyShell.py, its source shouldn't be
> there, isn't it?

I don't know!  linecache.py predates IDLE's existence, and every time I've
bumped into it it seemed like an optimization that created more problems
than it solved.  So if I were to pursue this, I'd look harder at tossing it
than fixing it.

But then I'm not sure why it's there either.  I expect that in your case,
it's actually traceback.py that's stuffing all of PyShell.py into the
linecache, as part of formatting the NameError exception, snaking thru
InteractiveInterpreter.showtraceback.  That last is hiding from you that
PyShell.py is in the true NameError traceback (you see an edited version of
it by the time it gets to the shell window).

now-you-understand-it-better-than-i-do<wink>-ly y'rs  - tim






More information about the Python-list mailing list