Idle's Shell: prompts and indents (was ...) Idle users please read

Terry Reedy tjreedy at udel.edu
Mon Jul 21 20:30:30 CEST 2014


On 7/21/2014 6:56 AM, Chris Angelico wrote:
> On Mon, Jul 21, 2014 at 7:00 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> In general, Idle should execute user code the same way that the interpreter
>> does, subject to the limitations of the different execution environment.
>
> Agreed, but I think the setting of prompts is a "different execution
> environment" case. It's a fundamental difference between batch mode
> and interactive, and Idle uses batch mode to implement interactive
> mode. So something like:
>
>>>> sys.ps1="Python> "
> "Setting sys.ps1 has no effect in Idle; see the Options menu."
>>>>
>
> It might not be possible, but if it is, it wouldn't break any actual
> viable use-cases.

It would be a lot of work for close to 0 gain. It could not work 
consistent without special-casing sys assignments. Consider

 >>> prompt1 = 'Me>'
 >>> setps1 = sys.ps1
 >>> setps1(prompt1)

;-(.


Idle cannot exactly imitate the interactive interpreter (II) because it 
does not execute code in exactly the same way. For instance,
http://bugs.python.org/issue21997
reported that fact that the sequence

    >>>def dodebug():
	    pdb.set_trace()
    >>>dodebug()

behaves differently in Idle and II. Not knowing the details of Idle 
(currently only available in the code), the OP claimed that this is an 
Idle bug.  It turns out that running dodebug indirectly

 >>> def run_code(code): exec(code, globals())
 >>> run('dodebug()')

*in the II* behaves like Idle.  The above is essentially how Idle runs 
code.  (The difference is that it substitutes a custom namespace 
designed to look like the globals() of a main modules, include having 
__name__ == '__main__'.)

Well, at least I know now, so I know how to review claims that Idle is 
buggy when it acts a bit differently than the II.  The exec abstraction 
has a few tiny leaks if one looks hard enough, such as with the 
debugger.  Using inspect to look at the frame stack would also show a 
difference.

-- 
Terry Jan Reedy




More information about the Python-list mailing list