classification
Title: sre_parse contains a confusing generic error message
Type: behavior Stage:
Components: Regular Expressions Versions: Python 3.2, Python 3.1, Python 3.0, Python 2.7, Python 2.6, Python 2.5, Python 2.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: torne (1)
Priority: Keywords patch

Created on 2009-08-05 17:14 by torne, last changed 2009-08-05 17:14 by torne.

Files
File name Uploaded Description Edit Remove
sre_error_msg.diff torne, 2009-08-05 17:14 patch with a nicer error message
Messages (1)
msg91324 - (view) Author: Torne Wuff (torne) Date: 2009-08-05 17:14
sre_parse raises an exception with the message "syntax error" - very
generic and confusing - in the case where something that looks like a
lookbehind assertion is invalid.

>>> import re
>>> re.match('(?<foo>.*)', 'foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/re.py", line 137, in match
    return _compile(pattern, flags).match(string)
  File "/usr/lib/python2.5/re.py", line 241, in _compile
    raise error, v # invalid expression
sre_constants.error: syntax error

This example is a typo for '(?P<foo>.*)' :)

This is the only case in sre_parse where the message "syntax error" is
used - the others are much more descriptive. Attached patch changes it
to "bad lookbehind assertion type: %s" for python 2.x head; should be
applied to 3.x also.
History
Date User Action Args
2009-08-05 17:14:38tornecreate