[New-bugs-announce] [issue22364] Unify error messages of re and regex

Serhiy Storchaka report at bugs.python.org
Mon Sep 8 14:22:56 CEST 2014


New submission from Serhiy Storchaka:

In some cases standard re module and third-party regex modules raise exceptions with different error messages.

1. re.match(re.compile('.'), 'A', re.I)

  re:    Cannot process flags argument with a compiled pattern
  regex: can't process flags argument with a compiled pattern

2. re.compile('(?P<foo_123')

  re:    unterminated name
  regex: missing >

3. re.compile('(?P<foo_123>a)(?P=foo_123')

  re:    unterminated name
  regex: missing )

4. regex.sub('(?P<a>x)', r'\g<a', 'xx')

  re:    unterminated group name
  regex: missing >

5. re.sub('(?P<a>x)', r'\g<', 'xx')

  re:    unterminated group name
  regex: bad group name

6. re.sub('(?P<a>x)', r'\g<a a>', 'xx')

  re:    bad character in group name
  regex: bad group name

7. re.sub('(?P<a>x)', r'\g<-1>', 'xx')

  re:    negative group number
  regex: bad group name

8. re.compile('(?P<foo_123>a)(?P=!)')

  re:    bad character in backref group name '!'
  regex: bad group name

9. re.sub('(?P<a>x)', r'\g', 'xx')

  re:    missing group name
  regex: missing <

10. re.compile('a\\')
    re.sub('x', '\\', 'x')

  re:    bogus escape (end of line)
  regex: bad escape

11. re.compile(r'\1')

  re:    bogus escape: '\1'
  regex: unknown group

12. re.compile('[a-')

  re:    unexpected end of regular expression
  regex: bad set

13. re.sub(b'.', 'b', b'c')

  re:    expected bytes, bytearray, or an object with the buffer interface, str found
  regex: expected bytes instance, str found

14. re.compile(r'\w', re.UNICODE | re.ASCII)

  re:    ASCII and UNICODE flags are incompatible
  regex: ASCII, LOCALE and UNICODE flags are mutually incompatible

15. re.compile('(abc')

  re:    unbalanced parenthesis
  regex: missing )

16. re.compile('abc)')

  re:    unbalanced parenthesis
  regex: trailing characters in pattern

17. re.compile(r'((.)\1+)')

  re:    cannot refer to open group
  regex: can't refer to an open group

Looks as in one case re messages are better, and in other cases regex messages are better. In any case it would be good to unify error messages in both modules.

----------
components: Library (Lib), Regular Expressions
messages: 226575
nosy: ezio.melotti, mrabarnett, pitrou, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Unify error messages of re and regex
type: enhancement
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22364>
_______________________________________


More information about the New-bugs-announce mailing list