fix: move watchdog Observer import to module level (#1200)#1201
Open
fix: move watchdog Observer import to module level (#1200)#1201
Conversation
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>
There was a problem hiding this comment.
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
Observerimport to the module-level third-party import block insrc/copilot_usage/interactive.py. - Removed the in-function
Observerimport fromstart_observer(). - Added a unit test asserting
Observeris available as a module-level attribute incopilot_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 |
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.
Closes #1200
Summary
Moves the lazy in-function
from watchdog.observers import Observerimport instart_observer()to the module-level import block ininteractive.py.Why
watchdogis a required package-level dependency — the lazy import provided no defensive value.start_observer().Changes
src/copilot_usage/interactive.py— movedfrom watchdog.observers import Observerto the third-party import section at the top of the module.tests/copilot_usage/test_interactive.py— added test confirmingObserveris a module-level attribute (not deferred).Warning
The following domains were blocked by the firewall during workflow execution:
astral.shpypi.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.