Issue2236

classification
Title: Interactive parser does not accept try ... except E as e: syntax
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: fwierzbicki Nosy List: fwierzbicki, jeff.allen
Priority: normal Keywords:

Created on 2014-12-13.09:54:05 by jeff.allen, last changed 2015-01-06.21:30:25 by fwierzbicki.

Messages
msg9230 (view) Author: Jeff Allen (jeff.allen) Date: 2014-12-13.09:54:05
The "as" keyword is not accepted in a try ... except construct. This should be available from Python 2.6.

>>> try:
...     f = open("x.tmp")
... except IOError as ex:
  File "<stdin>", line 3
    except IOError as ex:
                        ^
SyntaxError: mismatched input '<EOF>' expecting INDENT

A comma is acceptable to Jython for the same purpose.

Possibly an easy grammar fix since the code generation does not have to change. A test is clearly missing.
msg9231 (view) Author: Jeff Allen (jeff.allen) Date: 2014-12-13.10:31:16
That's odd. It works perfectly well when the source is a file, but not at the console. It is not sensitive to whether I use TAB or spaces.
>>> try:
...     print 1/0
... except ZeroDivisionError, e:
...     print "Ha!", e
...
Ha! integer division or modulo by zero
>>> try:
...     print 1/0
... except ZeroDivisionError as e:
  File "<stdin>", line 3
    except ZeroDivisionError as e:
                                 ^
SyntaxError: mismatched input '<EOF>' expecting INDENT

And the error message is strangely irrelevant.
msg9235 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2014-12-15.18:04:41
I'm guessing that this is interactive prompt only - unfortunately they are separate grammars and I sometimes miss an update. Should be an easy fix.
msg9319 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2015-01-06.21:30:25
Fixed in https://hg.python.org/jython/rev/8f083cde280f
History
Date User Action Args
2015-01-06 21:30:25fwierzbickisetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg9319
2015-01-06 20:45:11fwierzbickisettitle: try ... except E as e: syntax not accepted -> Interactive parser does not accept try ... except E as e: syntax
2014-12-15 18:04:42fwierzbickisetassignee: fwierzbicki
resolution: accepted
messages: + msg9235
nosy: + fwierzbicki
2014-12-13 10:31:17jeff.allensetmessages: + msg9231
2014-12-13 09:54:05jeff.allencreate