This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Compiling a regex with re.DEBUG should force a recompile
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, leewz, mrabarnett, pitrou, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-01-28 22:09 by leewz, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
re_debug_cache.patch pitrou, 2014-02-02 22:54
Messages (6)
msg209595 - (view) Author: Franklin? Lee (leewz) Date: 2014-01-28 22:09
Compiling a regex with the `re.DEBUG` flag indicates that the user wants to see the debug output. `re.compile` is cached, though, so there is the possibility of no output.

Example:
import re
re.compile('1',re.DEBUG) #expected output
re.compile('1',re.DEBUG) #no output
re.compile('',re.DEBUG)  #no output (empty regex)

The workaround is to call `re.purge()`, which may remove other cached regexes that are still in use.

(Background: I wanted to check for equivalence of regexes, and a StackOverflow answer suggested comparing their `re.DEBUG`. http://stackoverflow.com/a/21398362/2963903)
msg209617 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-29 07:08
See also issue17441.
msg210048 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-02-02 22:54
A simple workaround is to bypass the cache when DEBUG is passed. See attached patch.
(not sure this applies as a bug fix, but DEBUG probably isn't used in production anyway: the potential for breakage is low)
msg210158 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-03 20:01
New changeset a7b180d5df5f by Antoine Pitrou in branch '3.3':
Issue #20426: When passing the re.DEBUG flag, re.compile() displays the debug output every time it is called, regardless of the compilation cache.
http://hg.python.org/cpython/rev/a7b180d5df5f

New changeset a8bcfa290e68 by Antoine Pitrou in branch 'default':
Issue #20426: When passing the re.DEBUG flag, re.compile() displays the debug output every time it is called, regardless of the compilation cache.
http://hg.python.org/cpython/rev/a8bcfa290e68
msg210160 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-03 20:12
New changeset e47f6883dedf by Antoine Pitrou in branch '2.7':
Issue #20426: When passing the re.DEBUG flag, re.compile() displays the debug output every time it is called, regardless of the compilation cache.
http://hg.python.org/cpython/rev/e47f6883dedf
msg210161 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-02-03 20:13
Ok, I've fixed the bug in all branches. Thanks for reporting!
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64625
2014-02-03 20:13:29pitrousetstatus: open -> closed
resolution: fixed
messages: + msg210161

stage: patch review -> resolved
2014-02-03 20:12:53python-devsetmessages: + msg210160
2014-02-03 20:01:52python-devsetnosy: + python-dev
messages: + msg210158
2014-02-02 22:54:43pitrousetfiles: + re_debug_cache.patch
versions: + Python 2.7, Python 3.3, Python 3.4, - Python 3.5
messages: + msg210048

keywords: + patch
stage: test needed -> patch review
2014-01-29 07:08:56serhiy.storchakasetnosy: + serhiy.storchaka, pitrou
messages: + msg209617
2014-01-28 22:10:49ezio.melottisetstage: test needed
versions: + Python 3.5, - Python 3.3
2014-01-28 22:09:38leewzcreate