Skip to content

Commit 1b317dc

Browse files
committed
Fix type hints and expect re.error
1 parent 1c06da5 commit 1b317dc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

jsonpath/function_extensions/_pattern.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ def __init__(
4646
debug: bool = False,
4747
thread_safe: bool = False,
4848
):
49-
self.cache: LRUCache[str, Optional[re.Pattern[str]]] = (
49+
self.cache: LRUCache[str, Optional[re.Pattern]] = ( # type: ignore
5050
ThreadSafeLRUCache(capacity=cache_capacity)
5151
if thread_safe
5252
else LRUCache(capacity=cache_capacity)
5353
)
5454

5555
self.debug = debug
5656

57-
def check_cache(self, pattern: str) -> Optional[re.Pattern[str]]:
57+
def check_cache(self, pattern: str) -> Optional[re.Pattern]: # type: ignore
5858
"""Return a compiled re pattern if `pattern` is valid, or `None` otherwise."""
5959
try:
6060
_pattern = self.cache[pattern]

tests/test_regex_cache.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
try:
2+
import regex as re
3+
4+
REGEX_AVAILABLE = True
5+
except ImportError:
6+
import re # type: ignore
7+
8+
REGEX_AVAILABLE = False
9+
110
try:
211
import iregexp_check # noqa: F401
312

@@ -39,7 +48,7 @@ def test_debug_regex_patterns() -> None:
3948
search_func = Search(cache_capacity=2, debug=True)
4049
assert len(search_func.cache) == 0
4150

42-
with pytest.raises(JSONPathError):
51+
with pytest.raises((JSONPathError, re.error)):
4352
search_func("abcdef", "bc[")
4453

4554

0 commit comments

Comments
 (0)