This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: parser module doesn't like except-as syntax.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: benjamin.peterson, mark.dickinson
Priority: normal Keywords: patch

Created on 2010-06-30 14:36 by mark.dickinson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
parser_except_as_bug.patch mark.dickinson, 2010-06-30 14:38
issue9125.patch mark.dickinson, 2010-06-30 15:26
issue9125_v2.patch mark.dickinson, 2010-06-30 16:07
Messages (7)
msg108984 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-30 14:36
There seems to be a parser module bug for the except-as syntax in Python 2.7.  After applying the attached patch (which adds a test to test_parser), and running test_parser, I get:


======================================================================
FAIL: test_try_stmt (__main__.RoundtripLegalSyntaxTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_parser.py", line 237, in test_try_stmt
    self.check_suite("try: pass\nexcept A as e: pass\n")
  File "Lib/test/test_parser.py", line 38, in check_suite
    self.roundtrip(parser.suite, s)
  File "Lib/test/test_parser.py", line 20, in roundtrip
    self.fail("could not roundtrip %r: %s" % (s, why))
AssertionError: could not roundtrip 'try: pass\nexcept A as e: pass\n': Expected node type 12, got 1.
msg108985 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-30 14:38
Here's the correct test patch.
msg108986 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-30 14:41
Minimal steps to reproduce:

Python 2.7rc2+ (trunk:82378M, Jun 29 2010, 19:43:46) 
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import parser
>>> parser.sequence2st(parser.suite("try: pass\nexcept A as e: pass\n").totuple())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
parser.ParserError: Expected node type 12, got 1.
msg108988 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-30 15:26
Here's a fix.

Benjamin, is this okay for 2.7, or should it wait for 2.7.1?
msg108993 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-30 16:07
Updated patch, LBYL instead of EAFP flavour.

Oh, and this one actually compiles, too.
msg108994 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-06-30 16:12
Go ahead.
msg108995 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-06-30 16:37
Thanks, Benjamin.  Applied in r82400 (trunk) and r82401 (release26-maint).
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53371
2010-06-30 16:37:30mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg108995

stage: needs patch -> resolved
2010-06-30 16:12:39benjamin.petersonsetmessages: + msg108994
stage: commit review -> needs patch
2010-06-30 16:07:55mark.dickinsonsetfiles: + issue9125_v2.patch

messages: + msg108993
2010-06-30 15:49:12mark.dickinsonsetstage: needs patch -> commit review
2010-06-30 15:42:47mark.dickinsonsetassignee: mark.dickinson
2010-06-30 15:42:37mark.dickinsonsetversions: + Python 2.6
2010-06-30 15:26:31mark.dickinsonsetfiles: + issue9125.patch
nosy: + benjamin.peterson
messages: + msg108988

2010-06-30 14:41:47mark.dickinsonsetmessages: + msg108986
2010-06-30 14:38:13mark.dickinsonsetfiles: - parser_except_as_bug.patch
2010-06-30 14:38:07mark.dickinsonsetfiles: + parser_except_as_bug.patch

messages: + msg108985
2010-06-30 14:37:01mark.dickinsonsettype: behavior
components: + Library (Lib)
stage: needs patch
2010-06-30 14:36:31mark.dickinsoncreate