From 195c9234ba48aa51a471f0c6a6b459ab3819770b Mon Sep 17 00:00:00 2001 From: Andreas van Cranenburgh Date: Tue, 20 Dec 2022 19:35:01 +0100 Subject: [PATCH] include current notification level in cache key 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*+') :1: UserWarning: WARNING: Using re module. Reason: bad repetition operator: *+ re2.compile('a*+') Out[4]: re.compile('a*+') --- src/compile.pxi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compile.pxi b/src/compile.pxi index 7d8ca97..588584f 100644 --- a/src/compile.pxi +++ b/src/compile.pxi @@ -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)