Skip to content

Adopt ruff 0.16's default ruleset - #118

Open
WillKoehrsen wants to merge 2 commits into
mainfrom
ruff-016-default-ruleset
Open

Adopt ruff 0.16's default ruleset#118
WillKoehrsen wants to merge 2 commits into
mainfrom
ruff-016-default-ruleset

Conversation

@WillKoehrsen

@WillKoehrsen WillKoehrsen commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Bumps ruff from the >=0.5.0,<0.6 pin to ~=0.16 and switches from a hand maintained select to extend-select, so the project inherits ruff's new default rule set instead of pinning 5 rules and missing future additions.

The new defaults report 28 findings here. Three families are ignored with stated reasons and the remaining 9 are fixed.

Two datetime calls stay local on purpose

DTZ flags both, but UTC would be wrong:

  • get_daily_peak_report documents its default market_date as the caller's current date.
  • process_date handles a literal "today" the same way.

Only the calendar date survives the strftime in both, so switching to UTC would shift the default market day for anyone west of UTC. Both now carry a comment saying why they are local.

pytest.raises(Exception) left broad

B017 is correct that these are blind, but the client raises a bare Exception for API errors, so the assertions match reality. Narrowing them means adding a custom exception hierarchy, which is a public API change, so it is deferred along with TRY002.

Ignored families

Rule Why
RUF012 class level mutable defaults here are declarative config, not shared state
SIM117 nested with blocks read better than one merged statement
TRY002 a custom exception hierarchy is a separate, public facing change

Everything else

Mechanical: dict() and set() calls to literals, merged isinstance calls, unnecessary range starts, an f string conversion, and unused noqa directives. Notebook examples pick up the same literal cleanups since the pre commit hook lints Jupyter files.

One upgrade note: ruff 0.16's formatter also reformats Python inside Markdown fences. Neither make lint nor the pre-commit hook asks it to, so the README and CHANGELOG examples are deliberately untouched.

How to validate

  • make lint, plus uv run ruff check . to cover the whole repo including notebooks
  • uv run pyright
  • uv run pre-commit run --all-files
  • make test, which CI also runs on Python 3.10 through 3.13

Nothing here changes runtime behaviour. The only edits on executable paths are the two noqa comments above and literal rewrites that evaluate identically.

ruff 0.16 replaced its narrow legacy default with a broad curated default set,
so this drops the hand-maintained select in favour of extend-select. The project
now inherits the default rules and only names the families it needs on top:
pyflakes and pycodestyle in full, quotes, and import sorting.

Three families are ignored with reasons (declarative class attributes, nested
with blocks, and vanilla exception classes). The rest are fixed.

Two of the flagged datetime calls are deliberately local rather than UTC and now
say so. get_daily_peak_report documents its default market_date as the caller's
current date, and process_date treats a literal "today" the same way; only the
calendar date survives the strftime in both, so switching to UTC would shift the
default market day for callers west of UTC.

The pytest.raises(Exception) assertions match what the client actually raises,
which is a bare Exception for API errors. Narrowing them means introducing a
custom exception hierarchy, which is a public API change and is deferred with
TRY002.

The rest is mechanical: dict() and set() literals, merged isinstance calls,
unnecessary range starts, and dropped unused noqa directives.

Note that ruff 0.16's formatter also reformats Python inside Markdown fences.
Neither `make lint` nor the pre-commit hook asks it to, so the README and
CHANGELOG examples are deliberately left alone.

Verified: ruff check and format are clean over the package and the whole repo,
pyright reports no errors, the package imports, and all 153 tests collect. The
suite itself calls the live API, so it needs a key to run and was not executed.
CI runs `make lint`, which resolves ruff through uv.lock, while the pre-commit
hook resolves its own rev. A compatible-release pin lets the lockfile move to
0.16.x while the hook rev stays put, so both are now pinned to the same exact
version and the comment says why.
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