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: Poor error message when compiling invalid regex
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, mrabarnett, python-dev, r.david.murray, roysmith, serhiy.storchaka
Priority: normal Keywords: easy, patch

Created on 2013-03-03 13:56 by roysmith, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cpython-3.3-17341.patch Jason.Michalski, 2013-04-13 16:20 review
cpython-2.7-17341.patch Jason.Michalski, 2013-04-13 16:21 review
Messages (5)
msg183375 - (view) Author: Roy Smith (roysmith) Date: 2013-03-03 13:56
>>> re.compile('(?P=<foo>)')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/roy/env/python/lib/python2.7/re.py", line 190, in compile
    return _compile(pattern, flags)
  File "/home/roy/env/python/lib/python2.7/re.py", line 242, in _compile
    raise error, v # invalid expression
sre_constants.error: bad character in group name


The error here is that I put a "=" where it shouldn't be.  The error message is misleading.  The "group name" is the stuff between the <>'s.  That part's fine.  What's broken is the stuff outside of the <>'s.

Unclear if it's reasonable to expect such precise error reporting here, but this one seems particularly misleading, so opening a ticket to record the observation.
msg183381 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-03-03 14:33
The error is that '<' is not legal in a group name, and the parser is parsing the P= form.  The error message could be improved by including the bad character in the message.
msg183465 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-03-04 15:27
See also issue14462. It will be easier to include a full group name than an invalid character.
msg186930 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-14 17:09
New changeset 65db865c0851 by R David Murray in branch '3.3':
#17341: Include name in re error message about invalid group name.
http://hg.python.org/cpython/rev/65db865c0851

New changeset 227fed7a05d4 by R David Murray in branch 'default':
Merge #17341: Include name in re error message about invalid group name.
http://hg.python.org/cpython/rev/227fed7a05d4

New changeset bbb3aa45b4ea by R David Murray in branch '2.7':
#17341: Include name in re error message about invalid group name.
http://hg.python.org/cpython/rev/bbb3aa45b4ea
msg186931 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-04-14 17:13
Thanks Jason.
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61543
2013-04-14 17:13:33r.david.murraysetstatus: open -> closed
versions: + Python 3.3, Python 3.4
messages: + msg186931

resolution: fixed
stage: resolved
2013-04-14 17:09:50python-devsetnosy: + python-dev
messages: + msg186930
2013-04-13 16:21:06Jason.Michalskisetfiles: + cpython-2.7-17341.patch
2013-04-13 16:20:55Jason.Michalskisetfiles: + cpython-3.3-17341.patch
keywords: + patch
2013-03-04 15:27:53serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg183465
2013-03-03 14:33:25r.david.murraysetkeywords: + easy
nosy: + r.david.murray
messages: + msg183381

2013-03-03 13:56:15roysmithcreate