mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
Issue #20426: When passing the re.DEBUG flag, re.compile() displays the debug output every time it is called, regardless of the compilation cache.
This commit is contained in:
commit
c49672f25e
3 changed files with 26 additions and 8 deletions
17
Lib/re.py
17
Lib/re.py
|
@ -272,10 +272,12 @@ _pattern_type = type(sre_compile.compile("", 0))
|
|||
_MAXCACHE = 512
|
||||
def _compile(pattern, flags):
|
||||
# internal: compile pattern
|
||||
try:
|
||||
return _cache[type(pattern), pattern, flags]
|
||||
except KeyError:
|
||||
pass
|
||||
bypass_cache = flags & DEBUG
|
||||
if not bypass_cache:
|
||||
try:
|
||||
return _cache[type(pattern), pattern, flags]
|
||||
except KeyError:
|
||||
pass
|
||||
if isinstance(pattern, _pattern_type):
|
||||
if flags:
|
||||
raise ValueError(
|
||||
|
@ -284,9 +286,10 @@ def _compile(pattern, flags):
|
|||
if not sre_compile.isstring(pattern):
|
||||
raise TypeError("first argument must be string or compiled pattern")
|
||||
p = sre_compile.compile(pattern, flags)
|
||||
if len(_cache) >= _MAXCACHE:
|
||||
_cache.clear()
|
||||
_cache[type(pattern), pattern, flags] = p
|
||||
if not bypass_cache:
|
||||
if len(_cache) >= _MAXCACHE:
|
||||
_cache.clear()
|
||||
_cache[type(pattern), pattern, flags] = p
|
||||
return p
|
||||
|
||||
def _compile_repl(repl, pattern):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue