classification
Title: Correct stacklevel of warnings when compile regular expressions
Type: behavior Stage: resolved
Components: Library (Lib), Regular Expressions Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: ezio.melotti, mrabarnett, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-05-15 19:47 by serhiy.storchaka, last changed 2017-05-18 10:46 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1595 merged serhiy.storchaka, 2017-05-15 19:55
PR 1604 merged serhiy.storchaka, 2017-05-16 12:38
PR 1605 merged serhiy.storchaka, 2017-05-16 12:43
PR 1648 merged serhiy.storchaka, 2017-05-18 10:24
Messages (5)
msg293736 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-15 19:47
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)
msg293758 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-16 12:16
New changeset c7ac7280c321b3c1679fe5f657a6be0f86adf173 by Serhiy Storchaka in branch 'master':
bpo-30375: Correct the stacklevel of regex compiling warnings. (#1595)
https://github.com/python/cpython/commit/c7ac7280c321b3c1679fe5f657a6be0f86adf173
msg293768 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-16 15:16
New changeset 73fb45df0487144765808c5d25914c67232d83fe by Serhiy Storchaka in branch '3.6':
[3.6] bpo-30375: Correct the stacklevel of regex compiling warnings. (GH-1595) (#1604)
https://github.com/python/cpython/commit/73fb45df0487144765808c5d25914c67232d83fe
msg293769 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-16 15:16
New changeset 24b5ed230df65f6a1f9d8dd0c4409377576113d9 by Serhiy Storchaka in branch '3.5':
[3.5] bpo-30375: Correct the stacklevel of regex compiling warnings. (GH-1595) (#1605)
https://github.com/python/cpython/commit/24b5ed230df65f6a1f9d8dd0c4409377576113d9
msg293918 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-18 10:46
New changeset dfcfc915787def056e225fb22ad5a5ee8da4052f by Serhiy Storchaka in branch '2.7':
[2.7] bpo-30375: Correct the stacklevel of regex compiling warnings. (#1595) (#1648)
https://github.com/python/cpython/commit/dfcfc915787def056e225fb22ad5a5ee8da4052f
History
Date User Action Args
2017-05-18 10:46:58serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-05-18 10:46:20serhiy.storchakasetmessages: + msg293918
2017-05-18 10:24:58serhiy.storchakasetpull_requests: + pull_request1743
2017-05-16 15:16:55serhiy.storchakasetmessages: + msg293769
2017-05-16 15:16:29serhiy.storchakasetmessages: + msg293768
2017-05-16 12:46:02serhiy.storchakasetversions: + Python 2.7
2017-05-16 12:43:24serhiy.storchakasetpull_requests: + pull_request1696
2017-05-16 12:38:47serhiy.storchakasetpull_requests: + pull_request1695
2017-05-16 12:16:18serhiy.storchakasetmessages: + msg293758
2017-05-15 19:55:58serhiy.storchakasetpull_requests: + pull_request1689
2017-05-15 19:47:50serhiy.storchakacreate