|
32 | 32 | from argparse import ArgumentParser, RawDescriptionHelpFormatter
|
33 | 33 | from io import StringIO
|
34 | 34 | from textwrap import dedent
|
| 35 | +from typing import TYPE_CHECKING |
35 | 36 |
|
| 37 | +from watchdog.observers.api import BaseObserverSubclassCallable |
36 | 38 | from watchdog.utils import WatchdogShutdown, load_class
|
37 | 39 | from watchdog.version import VERSION_STRING
|
38 | 40 |
|
@@ -265,11 +267,12 @@ def tricks_from(args):
|
265 | 267 | """
|
266 | 268 | Command to execute tricks from a tricks configuration file.
|
267 | 269 | """
|
| 270 | + Observer: BaseObserverSubclassCallable |
268 | 271 | if args.debug_force_polling:
|
269 | 272 | from watchdog.observers.polling import PollingObserver as Observer
|
270 | 273 | elif args.debug_force_kqueue:
|
271 | 274 | from watchdog.observers.kqueue import KqueueObserver as Observer
|
272 |
| - elif args.debug_force_winapi: |
| 275 | + elif (not TYPE_CHECKING and args.debug_force_winapi) or (TYPE_CHECKING and sys.platform.startswith("win")): |
273 | 276 | from watchdog.observers.read_directory_changes import WindowsApiObserver as Observer
|
274 | 277 | elif args.debug_force_inotify:
|
275 | 278 | from watchdog.observers.inotify import InotifyObserver as Observer
|
@@ -376,8 +379,8 @@ def tricks_generate_yaml(args):
|
376 | 379 | else:
|
377 | 380 | if not os.path.exists(args.append_to_file):
|
378 | 381 | content = header + content
|
379 |
| - with open(args.append_to_file, "a", encoding="utf-8") as output: |
380 |
| - output.write(content) |
| 382 | + with open(args.append_to_file, "a", encoding="utf-8") as file: |
| 383 | + file.write(content) |
381 | 384 |
|
382 | 385 |
|
383 | 386 | @command(
|
@@ -471,11 +474,13 @@ def log(args):
|
471 | 474 | ignore_patterns=ignore_patterns,
|
472 | 475 | ignore_directories=args.ignore_directories,
|
473 | 476 | )
|
| 477 | + |
| 478 | + Observer: BaseObserverSubclassCallable |
474 | 479 | if args.debug_force_polling:
|
475 | 480 | from watchdog.observers.polling import PollingObserver as Observer
|
476 | 481 | elif args.debug_force_kqueue:
|
477 | 482 | from watchdog.observers.kqueue import KqueueObserver as Observer
|
478 |
| - elif args.debug_force_winapi: |
| 483 | + elif (not TYPE_CHECKING and args.debug_force_winapi) or (TYPE_CHECKING and sys.platform.startswith("win")): |
479 | 484 | from watchdog.observers.read_directory_changes import WindowsApiObserver as Observer
|
480 | 485 | elif args.debug_force_inotify:
|
481 | 486 | from watchdog.observers.inotify import InotifyObserver as Observer
|
@@ -585,6 +590,7 @@ def shell_command(args):
|
585 | 590 | if not args.command:
|
586 | 591 | args.command = None
|
587 | 592 |
|
| 593 | + Observer: BaseObserverSubclassCallable |
588 | 594 | if args.debug_force_polling:
|
589 | 595 | from watchdog.observers.polling import PollingObserver as Observer
|
590 | 596 | else:
|
@@ -704,6 +710,7 @@ def auto_restart(args):
|
704 | 710 | Command to start a long-running subprocess and restart it on matched events.
|
705 | 711 | """
|
706 | 712 |
|
| 713 | + Observer: BaseObserverSubclassCallable |
707 | 714 | if args.debug_force_polling:
|
708 | 715 | from watchdog.observers.polling import PollingObserver as Observer
|
709 | 716 | else:
|
|
0 commit comments