From 23388375b7495e70a5163986a401e526c5543b7f Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Mon, 9 Oct 2023 14:29:10 -0700 Subject: [PATCH] fix: mypy errors introduced by #1012 (#1014) --- src/watchdog/observers/polling.py | 4 ++-- src/watchdog/utils/dirsnapshot.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/watchdog/observers/polling.py b/src/watchdog/observers/polling.py index 466cd821..af74a6c5 100644 --- a/src/watchdog/observers/polling.py +++ b/src/watchdog/observers/polling.py @@ -49,7 +49,7 @@ FileMovedEvent, ) from watchdog.observers.api import DEFAULT_EMITTER_TIMEOUT, DEFAULT_OBSERVER_TIMEOUT, BaseObserver, EventEmitter -from watchdog.utils.dirsnapshot import DirectorySnapshot, DirectorySnapshotDiff +from watchdog.utils.dirsnapshot import DirectorySnapshot, DirectorySnapshotDiff, EmptyDirectorySnapshot class PollingEmitter(EventEmitter): @@ -68,7 +68,7 @@ def __init__( listdir=os.scandir, ): super().__init__(event_queue, watch, timeout, event_filter) - self._snapshot = None + self._snapshot: DirectorySnapshot = EmptyDirectorySnapshot() self._lock = threading.Lock() self._take_snapshot = lambda: DirectorySnapshot( self.watch.path, self.watch.is_recursive, stat=stat, listdir=listdir diff --git a/src/watchdog/utils/dirsnapshot.py b/src/watchdog/utils/dirsnapshot.py index 282487ba..69f41608 100644 --- a/src/watchdog/utils/dirsnapshot.py +++ b/src/watchdog/utils/dirsnapshot.py @@ -356,12 +356,15 @@ def __repr__(self) -> str: return str(self._stat_info) -class EmptyDirectorySnapshot: +class EmptyDirectorySnapshot(DirectorySnapshot): """Class to implement an empty snapshot. This is used together with DirectorySnapshot and DirectorySnapshotDiff in order to get all the files/folders in the directory as created. """ + def __init__(self): + pass + @staticmethod def path(_: Any) -> None: """Mock up method to return the path of the received inode. As the snapshot