New submission from Serhiy Storchaka:
When compile a regular expression with groups or conditionals emitted warnings
point on lines in the re module implementation rather than the line in user
code.
>>> import re
>>> re.compile('x(?i)')
__main__:1: DeprecationWarning: Flags not at the start of the expression x(?i)
re.compile('x(?i)', re.IGNORECASE)
>>> re.compile('(x(?i))')
/home/serhiy/py/cpython/Lib/re.py:281: DeprecationWarning: Flags not at the
start of the expression (x(?i))
p = sre_compile.compile(pattern, flags)
re.compile('(x(?i))', re.IGNORECASE)
>>> re.compile('((x(?i)))')
/home/serhiy/py/cpython/Lib/sre_parse.py:889: DeprecationWarning: Flags not at
the start of the expression ((x(?i)))
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, False)
re.compile('((x(?i)))', re.IGNORECASE)
Proposed patch fixes this:
>>> import re
>>> re.compile('x(?i)')
__main__:1: DeprecationWarning: Flags not at the start of the expression x(?i)
re.compile('x(?i)', re.IGNORECASE)
>>> re.compile('(x(?i))')
__main__:1: DeprecationWarning: Flags not at the start of the expression (x(?i))
re.compile('(x(?i))', re.IGNORECASE)
>>> re.compile('((x(?i)))')
__main__:1: DeprecationWarning: Flags not at the start of the expression
((x(?i)))
re.compile('((x(?i)))', re.IGNORECASE)
----------
assignee: serhiy.storchaka
components: Library (Lib), Regular Expressions
messages: 293736
nosy: ezio.melotti, mrabarnett, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Correct stacklevel of warnings when compile regular expressions
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue30375>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com