[New-bugs-announce] [issue30375] Correct stacklevel of warnings when compile regular expressions

Serhiy Storchaka report at bugs.python.org
Mon May 15 15:47:50 EDT 2017


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 <report at bugs.python.org>
<http://bugs.python.org/issue30375>
_______________________________________


More information about the New-bugs-announce mailing list