Skip to content

Conversation

@danfimov
Copy link
Contributor

@danfimov danfimov commented Nov 24, 2025

When taskiq scheduler --help called without watchdog installed, this issue occur:

Traceback (most recent call last):
  File "/home/s3rius/projects/github/taskiq/taskiq/.venv/bin/taskiq", line 10, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/s3rius/projects/github/taskiq/taskiq/taskiq/__main__.py", line 47, in main
    cmd_class = entrypoint.load()
  File "/home/s3rius/.local/share/uv/python/cpython-3.13.1-linux-x86_64-gnu/lib/python3.13/importlib/metadata/__init__.py", line 179, in load
    module = import_module(match.group('module'))
  File "/home/s3rius/.local/share/uv/python/cpython-3.13.1-linux-x86_64-gnu/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/s3rius/projects/github/taskiq/taskiq/taskiq/cli/worker/cmd.py", line 6, in <module>
    from taskiq.cli.worker.run import run_worker
  File "/home/s3rius/projects/github/taskiq/taskiq/taskiq/cli/worker/run.py", line 15, in <module>
    from taskiq.cli.worker.process_manager import ProcessManager
  File "/home/s3rius/projects/github/taskiq/taskiq/taskiq/cli/worker/process_manager.py", line 149, in <module>
    class ProcessManager:
    ...<139 lines>...
                        )
  File "/home/s3rius/projects/github/taskiq/taskiq/taskiq/cli/worker/process_manager.py", line 162, in ProcessManager
    observer: Observer | None = None,  # type: ignore[valid-type]
              ~~~~~~~~~^~~~~~
TypeError: unsupported operand type(s) for |: 'NoneType' and 'NoneType'

This pull request fixes it by using old-style type hint Optional

Copilot AI review requested due to automatic review settings November 24, 2025 16:17
Copilot finished reviewing on behalf of danfimov November 24, 2025 16:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a type-checking issue by changing the type hint for the observer parameter from the modern PEP 604 union syntax (Observer | None) to the old-style Optional[Observer]. This change is specifically made for a conditionally defined type (Observer) that can be None when the optional watchdog dependency is not installed, which appears to cause issues with type checkers.

  • Changed observer parameter type hint to use Optional[Observer] instead of Observer | None
  • Added Optional import from typing module
  • Added # noqa: UP045 to suppress ruff's modernization suggestion

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danfimov danfimov force-pushed the fix-crash-with-observer branch from e2090a6 to ecec5e4 Compare November 25, 2025 09:06
@s3rius s3rius merged commit 5140315 into taskiq-python:master Nov 25, 2025
27 checks passed
@danfimov danfimov changed the title fix: use old-style Optional for case with Observer type hint fix: type hint when whatchfiles library is not installed Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants