Skip to content

Commit

Permalink
include current notification level in cache key
Browse files Browse the repository at this point in the history
this prevents a cached regular expression being used that was created
with a different notification level.

For example, the following now generates the expected warning:

    In [1]: import re2
    In [2]: re2.compile('a*+')
    Out[2]: re.compile('a*+')
    In [3]: re2.set_fallback_notification(re2.FALLBACK_WARNING)
    In [4]: re2.compile('a*+')
    <ipython-input-5-041122e221c7>:1: UserWarning: WARNING: Using re module. Reason: bad repetition operator: *+
      re2.compile('a*+')
    Out[4]: re.compile('a*+')
  • Loading branch information
andreasvc committed Dec 20, 2022
1 parent 6bb18c2 commit 195c923
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/compile.pxi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

def compile(pattern, int flags=0, int max_mem=8388608):
cachekey = (type(pattern), pattern, flags)
cachekey = (type(pattern), pattern, flags, current_notification)
if cachekey in _cache:
return _cache[cachekey]
p = _compile(pattern, flags, max_mem)
Expand Down

0 comments on commit 195c923

Please sign in to comment.