Allow scheduling watches without an initial event handler (fixes #1039)#1169
Open
Prosperibe12 wants to merge 2 commits into
Open
Conversation
…khargosh#1039) Prior to this commit, Observer.schedule always registered the given event_handler; passing None stored None in the handler set, which could raise if events were dispatched, and there was no supported way to attach only add_handler_for_watch after creating the watch. This commit treats None as no initial handler (skip registration), adds NoOpEventHandler and noop_event_handler for typing-friendly call sites, mirrors overloads on FSEventsObserver.schedule, fixes unschedule when no handlers are registered
6b29489 to
ba58e8d
Compare
Contributor
Author
|
@BoboTiG I will appreaciate a review on this pr |
Contributor
Author
|
@BoboTiG commenting again, maybe you have missed the previous message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 Description
Implements handler-less watches:
Observer.schedule(None, path, …)(orschedule(noop_event_handler, path, …)) registers the watch without an initial handler; handlers are added later withadd_handler_for_watch. Fixesunschedulewhen no handlers exist.💁 Why is this change needed?
Several call sites need one shared watch on a path while attaching handlers from different subroutines. Previously
schedulealways registered an initial handler, and passingNonestoredNonein the handler set, which could break dispatch. This implements the approach discussed on the issue: optionalNone/ no-op handler at schedule time, thenadd_handler_for_watchfor real handlers.📎 Issue (#1039)
✨ Type of change
📋 New feature implementation
BaseObserver.schedule: skip_add_handler_for_watchwhenevent_handler is None;@overloadforFileSystemEventHandlervsNone.watchdog.events:NoOpEventHandler,noop_event_handler.BaseObserver.unschedule: use_handlers.pop(watch, None).FSEventsObserver.schedule: same overloads /FileSystemEventHandler | Noneas the base class.