[Python-bugs-list] [ python-Bugs-768859 ] odd behavior of try-break-finally on IDLE

SourceForge.net noreply@sourceforge.net
Wed, 09 Jul 2003 22:17:55 -0700


Bugs item #768859, was opened at 2003-07-09 22:35
Message generated for change (Comment added) made by kbk
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=768859&group_id=5470

Category: IDLE
Group: Python 2.3
>Status: Pending
>Resolution: Works For Me
Priority: 6
Submitted By: George Yoshida (quiver)
Assigned to: Kurt B. Kaiser (kbk)
Summary: odd behavior of try-break-finally on IDLE

Initial Comment:
I've found an odd behavior of try-break-finally 
expression inside a function on IDLE.
See the code below.

Python 2.3b2 (#43, Jun 29 2003, 16:43:04) [MSC 
v.1200 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more 
information.
IDLE 1.0b2  
>>> try:
	break
finally:
	print "finally"
	
SyntaxError: 'break' outside loop

As you expect, you get SyntaxError.
However, if you wrap them in a function,

>>> def foo():
	try:
		break
	finally:
		print "finally"

after pressing <ENTER> a few times, IDLE exits suddenly
( and silently).

If you do the same thing from the command line, there's 
no problem.
You get the SyntaxError in either case.

On an older IDLE, the error messages are much more 
verbose.
Although I've tested this on a localized(Japanese 
enhanced) Python,
I guess the result will be the same.

Python 2.2.3 (SJIS enhanced) (#42, Jun  8 2003, 
01:46:45) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more 
information.
IDLE 0.8 -- press F1 for help
>>> def foo():
	try:
		break
	finally:
		print "finally"

    Exception in Tkinter callback
Traceback (most recent call last):
  File "c:\Python22jp\lib\lib-tk\Tkinter.py", line 1316, in 
__call__
    return apply(self.func, args)
  File "C:\python22jp\Tools\idle\PyShell.py", line 595, in 
enter_callback
    self.runit()
  File "C:\python22jp\Tools\idle\PyShell.py", line 614, in 
runit
    more = self.interp.runsource(line)
  File "C:\python22jp\Tools\idle\PyShell.py", line 192, in 
runsource
    return InteractiveInterpreter.runsource(self, source, 
filename)
  File "c:\Python22jp\lib\code.py", line 79, in runsource
    self.showsyntaxerror(filename)
  File "C:\python22jp\Tools\idle\PyShell.py", line 219, in 
showsyntaxerror
    pos = "iomark linestart + %d lines + %d chars" % 
(lineno-1,
TypeError: unsupported operand type(s) for -
: 'NoneType' and 'int'

----------------------------------------------------------------------

>Comment By: Kurt B. Kaiser (kbk)
Date: 2003-07-10 00:17

Message:
Logged In: YES 
user_id=149084

I have tried the current CVS on both Windows and
Linux and do not see the problem since fixing 
bug # 767794 yesterday.

You have to be sure you are running the fixed 
version of IDLE.  On Linux the default will be to
run  /usr/local/lib/Python2.3/idlelib/PyShell.py.

Python 2.3b2 (#43, Jun 29 2003, 16:43:04) [MSC v.1200 32 
bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
IDLE 1.0b2      
>>> def foo():
	try:
		break
	finally:
		print 'break'
		
SyntaxError: 'break' outside loop
>>> def bar():
	try:
		continue
	finally:
		print 'bar'
		
SyntaxError: 'continue' not properly in loop
>>> 


----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-07-09 23:39

Message:
Logged In: YES 
user_id=80475

Verified that the behavior persists even after the 
recent 'break' fix for Py2.3b2+.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=768859&group_id=5470