Message226575
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. |
|
Date |
User |
Action |
Args |
2014-09-08 12:22:56 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, pitrou, ezio.melotti, mrabarnett |
2014-09-08 12:22:56 | serhiy.storchaka | set | messageid: <1410178976.27.0.421938794422.issue22364@psf.upfronthosting.co.za> |
2014-09-08 12:22:56 | serhiy.storchaka | link | issue22364 messages |
2014-09-08 12:22:55 | serhiy.storchaka | create | |
|