Skip to content

Commit 9e1daa8

Browse files
spacemanspiff2007cknd
authored andcommitted
small optimize for util.match
1 parent 115c669 commit 9e1daa8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

stackprinter/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import colorsys
55
from collections import OrderedDict
66

7+
78
def match(string, patterns):
8-
if not isinstance(string, str):
9+
if patterns is None or not isinstance(string, str):
910
return False
1011
if isinstance(patterns, str):
1112
patterns = [patterns]
12-
elif patterns is None:
13-
return False
14-
return any([bool(re.search(p, string)) for p in patterns])
13+
14+
return any(map(lambda p: re.search(p, string), patterns))
15+
1516

1617
def inspect_callable(f):
1718
"""

tests/test_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from stackprinter.utils import match
2+
import re
3+
4+
5+
def test_match():
6+
assert match('my/ignored/path', None) is False
7+
assert match('my/ignored/path', 'ignored')
8+
assert match('my/ignored/path', ['not', 'ignored'])
9+
assert match('my/ignored/path', [re.compile('not ignored'), re.compile('ignored')])

0 commit comments

Comments
 (0)