Skip to content

fix: move watchdog Observer import to module level (#1200)#1201

Open
microsasa wants to merge 1 commit intomainfrom
fix/1200-move-watchdog-import-to-module-level-8a99e422571fc370
Open

fix: move watchdog Observer import to module level (#1200)#1201
microsasa wants to merge 1 commit intomainfrom
fix/1200-move-watchdog-import-to-module-level-8a99e422571fc370

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #1200

Summary

Moves the lazy in-function from watchdog.observers import Observer import in start_observer() to the module-level import block in interactive.py.

Why

  • watchdog is a required package-level dependency — the lazy import provided no defensive value.
  • Violates the coding guideline: "Lazy in-function imports are banned except where already present."
  • Import errors now surface at process start rather than at first call to start_observer().

Changes

  • src/copilot_usage/interactive.py — moved from watchdog.observers import Observer to the third-party import section at the top of the module.
  • tests/copilot_usage/test_interactive.py — added test confirming Observer is a module-level attribute (not deferred).

Warning

⚠️ Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • astral.sh
  • pypi.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "astral.sh"
    - "pypi.org"

See Network Configuration for more information.

Generated by Issue Implementer · ● 6.7M ·

Move the lazy in-function import of Observer from watchdog.observers
to the module-level import block, fixing a coding guideline violation.

The watchdog package is a required dependency (listed in pyproject.toml
under [project] dependencies), so the lazy import provided no defensive
value and violated the ban on lazy in-function imports.

Add test_interactive.py with a test confirming Observer is available as
a module-level attribute.

Closes #1200

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 6, 2026 09:48
@microsasa microsasa added the aw Created by agentic workflow label May 6, 2026
@microsasa microsasa enabled auto-merge May 6, 2026 09:48
Copy link
Copy Markdown

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

Moves the watchdog.observers.Observer import in copilot_usage.interactive from a lazy in-function import to a module-level import, aligning with the repo’s “no lazy imports” guideline and making dependency/import failures surface earlier.

Changes:

  • Hoisted Observer import to the module-level third-party import block in src/copilot_usage/interactive.py.
  • Removed the in-function Observer import from start_observer().
  • Added a unit test asserting Observer is available as a module-level attribute in copilot_usage.interactive.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/copilot_usage/interactive.py Hoists Observer import to module scope and removes the lazy in-function import.
tests/copilot_usage/test_interactive.py Adds a test to confirm Observer is imported at module level.

Comment on lines +3 to +6
import copilot_usage.interactive as _interactive_mod
from watchdog.observers import Observer


from rich.console import Console
from rich.table import Table
from rich.text import Text
from watchdog.observers import Observer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][code health] start_observer in interactive.py uses a lazy in-function import — guideline violation, same class as #1183

2 participants