Skip to content

fix(lint): move module-level statements out of import blocks - #225

Open
Caldalis wants to merge 1 commit into
OpenBMB:mainfrom
Caldalis:fix/module-level-import-order
Open

fix(lint): move module-level statements out of import blocks#225
Caldalis wants to merge 1 commit into
OpenBMB:mainfrom
Caldalis:fix/module-level-import-order

Conversation

@Caldalis

Copy link
Copy Markdown

Problem

Two module-level statements sit inside import blocks, which makes every import that follows them a module-level import after code (E402):

  • backend/app/core/agent_loop.py:62logger = logging.getLogger(__name__) is placed mid-block, so the 9 imports after it are flagged.
  • backend/app/api/skills.py:59_CHANNEL_LABELS = {...} does the same for the 4 imports after it.
    backend/tests/test_channel_routing.py also has two f-strings with no placeholders (F541).
$ ruff check backend --select E4,E7,E9,F,W
Found 15 errors.

All 15 were introduced in 008fff3.

Change

Move both statements below their import blocks and drop the f prefix from the two constant URLs. No behaviour changes.

Why this is safe

  • Neither value is read at import time: logger is only used in agent_loop.py:837, _CHANNEL_LABELS only in skills.py:256 and :296.
  • Nothing imports these symbols, so there is no circular-import path that could depend on their position — other modules only import AgentLoop, create_skill and router.
  • agent_cw is a hard-coded id throughout test_channel_routing.py (see line 48), so the two f-strings were leftovers rather than a missing interpolation.

logger is moved rather than removed, since it has a real call site.

Note on visibility

These findings do not all show up in a default ruff check backend run. [tool.ruff] currently sets only line-length and target-version, so the active rule set is whatever the installed ruff defaults to; on ruff 0.16.4 that is 413 rules and 1983 findings, and E402 is not among the enabled rules. The 13 E402 findings above are therefore invisible under the current configuration and only surface when the rule set is stated explicitly.

Pinning that rule set is a separate concern and I am happy to open a follow-up for it; this PR only fixes the code. configuration and only surface when the rule set is stated explicitly.

Pinning that rule set is a separate concern and I am happy to open a follow-up for it; this PR only fixes the code.

Tests

Run on this branch:

  • ruff check backend --select E4,E7,E9,F,W — passes (was 15 errors)
  • pytest backend/tests — 1997 passed
  • python -c "import app.core.agent_loop, app.api.skills" — both import cleanly

UI validation

Not applicable: no route, template or rendered output is affected.

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.

1 participant