Skip to content

Commit 75fe2d2

Browse files
authored
Convert regexes of type str to list (#831)
* convert regexes of type str to list * > tests added > updated changelog.rst
1 parent c74381c commit 75fe2d2

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

changelog.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Changelog
88

99
2021-xx-xx • `full history <https://github.com/gorakhargosh/watchdog/compare/v2.1.4...master>`__
1010

11-
-
12-
- Thanks to our beloved contributors: @
11+
- convert regexes of type str to list. (`#831 <https://github.com/gorakhargosh/watchdog/pull/831>`_)
12+
- Thanks to our beloved contributors: @unique1o1
1313

1414
2.1.4
1515
~~~~~

src/watchdog/events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ def __init__(self, regexes=None, ignore_regexes=None,
418418

419419
if regexes is None:
420420
regexes = [r".*"]
421+
elif isinstance(regexes, str):
422+
regexes = [regexes]
421423
if ignore_regexes is None:
422424
ignore_regexes = []
423425
if case_sensitive:

tests/test_regex_matching_event_handler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
path_1 = '/path/xyz'
3636
path_2 = '/path/abc'
3737
g_allowed_regexes = [r".*\.py", r".*\.txt"]
38+
g_allowed_str_regexes = r".*\.py"
3839
g_ignore_regexes = [r".*\.pyc"]
3940

4041

@@ -186,6 +187,12 @@ def test_regexes():
186187
assert [r.pattern for r in handler1.regexes] == g_allowed_regexes
187188

188189

190+
def test_str_regexes():
191+
handler1 = RegexMatchingEventHandler(g_allowed_str_regexes,
192+
g_ignore_regexes, True)
193+
assert [r.pattern for r in handler1.regexes] == [g_allowed_str_regexes]
194+
195+
189196
def test_logging_event_handler_dispatch():
190197

191198
class _TestableEventHandler(LoggingEventHandler):

0 commit comments

Comments
 (0)