Skip to content

test: satisfy ruff 0.17 in test_ibkr.py (unblocks #169) - #170

Merged
extrange merged 1 commit into
masterfrom
fix/ruff-0.17-lint-test-ibkr
Nov 12, 2026
Merged

extrange merged 1 commit into
masterfrom
fix/ruff-0.17-lint-test-ibkr

Conversation

@extrange

@extrange extrange commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Problem

renovate/lock-file-maintenance (PR #169) is green everywhere except Lint and type check. The lockfile refresh moves ruff from 0.11.13 to 0.17.4, and the newer ruff flags four pre-existing issues in tests/test_ibkr.py:

tests/test_ibkr.py:1:1: I001 Import block is un-sorted or un-formatted
tests/test_ibkr.py:11:19: TRY002 Create your own exception
tests/test_ibkr.py:14:9: S110 `try`-`except`-`pass` detected, consider logging the exception
tests/test_ibkr.py:14:16: BLE001 Do not catch blind exception: `Exception`

Nothing in the test was broken by the dependency bump — the lint gate simply sees more than it used to.

Approach

Smallest change that clears all four without changing the test's intent (retry up to three times, then fail loudly):

  • sort the imports (I001);
  • add a dedicated IBKRConnectionError instead of raising bare Exception (TRY002);
  • catch OSError — what connectAsync actually raises: ConnectionRefusedError, ConnectionError and TimeoutError are all OSError subclasses — and re-raise with the caught error as the cause, so neither the blind catch nor the silent pass remains (S110, BLE001).

Evidence

Run locally in a clean clone, on the PR's own ruff version:

$ uv run --frozen --with ruff==0.17.4 ruff check .
All checks passed!

$ uv run --frozen --with ruff==0.17.4 ruff format --check .
3 files already formatted

$ uv run --frozen pyright
0 errors, 0 warnings, 0 informations

Also re-checked against master's locked ruff 0.11.13 — still passes.

Behaviour check (no gateway on localhost:8888 here): the test retries three times, catches each OSError, and fails with IBKRConnectionError chained to the connection error — same behaviour as before, now with a usable message.

FAILED tests/test_ibkr.py::test_ib_connection - tests.test_ibkr.IBKRConnectionError

Unrelated and pre-existing: importing ib_insync on Python 3.15 raises RuntimeError: There is no current event loop inside eventkit at collection time; on 3.12 the module imports fine. Not touched here.

Merging this should let PR #169 rebase and go green.

Ruff 0.17 flags four pre-existing issues in the IBKR connection test:
unsorted imports (I001), a bare Exception (TRY002), and a silent
try/except/pass (S110 + BLE001). The lock-file-maintenance bump to ruff
0.17.4 turns these into a failing lint gate.

Sort the imports, raise a dedicated IBKRConnectionError, and catch the
OSError the client actually raises while keeping the caught error as the
cause.
Copilot AI balanced review requested due to automatic review settings November 12, 2026 06:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@extrange
extrange merged commit df0c9ec into master Nov 12, 2026
5 checks passed
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