Skip to content

Commit

Permalink
Ensure ObservedWatch.path is a string (fix gorakhargosh#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
rec committed Apr 28, 2020
1 parent 077d5b1 commit fa78e7e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog

2020-0x-xx • `full history <https://github.com/gorakhargosh/watchdog/compare/v0.10.2...master>`__

- Ensure ObservedWatch.path is a string (`#655 <https://github.com/gorakhargosh/watchdog/pull/651>`_)
- [inotify] Allow to monitor single file (`#655 <https://github.com/gorakhargosh/watchdog/pull/655>`__)
- Thanks to our beloved contributors: @brant-ruan

Expand Down
9 changes: 8 additions & 1 deletion src/watchdog/observers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
from watchdog.utils import BaseThread
from watchdog.utils.compat import queue
from watchdog.utils.bricks import SkipRepeatsQueue
try:
from pathlib import Path as _PATH_CLASSES
except ImportError:
_PATH_CLASSES = ()

DEFAULT_EMITTER_TIMEOUT = 1 # in seconds.
DEFAULT_OBSERVER_TIMEOUT = 1 # in seconds.
Expand All @@ -46,7 +50,10 @@ class ObservedWatch(object):
"""

def __init__(self, path, recursive):
self._path = path
if isinstance(path, _PATH_CLASSES):
self._path = str(path)
else:
self._path = path
self._is_recursive = recursive

@property
Expand Down
8 changes: 8 additions & 0 deletions tests/test_observers_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
)


def test_observer_constructor():
try:
from pathlib import Path
except ImportError:
return
ObservedWatch(Path('/foobar'), True)


def test_observer__eq__():
watch1 = ObservedWatch('/foobar', True)
watch2 = ObservedWatch('/foobar', True)
Expand Down

0 comments on commit fa78e7e

Please sign in to comment.