Skip to content

chore(lint): treat typer.Option and fastapi.Form as immutable for B008 - #184

Merged
vsn411 merged 2 commits into
secfoo-com:mainfrom
onetwothird:gitranks/166-lint-silence-b008-false-positives-for
Nov 21, 2026
Merged

vsn411 merged 2 commits into
secfoo-com:mainfrom
onetwothird:gitranks/166-lint-silence-b008-false-positives-for

Conversation

@onetwothird

@onetwothird onetwothird commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #166

What does this change, and why?

ruff flags 18 B008 findings (function call in an argument default): 16 for typer.Option(...) in src/secfoo/cli.py and 2 for FastAPI's Form(...) in src/secfoo/web/routes/assessments.py. Those calls are meant to be used as parameter defaults — they describe the parameter rather than create shared mutable state — so these are false positives.

The repo had no ruff configuration yet, so this adds a [tool.ruff.lint.flake8-bugbear] section to pyproject.toml with extend-immutable-calls = ["typer.Option", "fastapi.Form"]. Only the two calls that actually trigger the rule are listed (no typer.Argument, Depends or Query usages are flagged today). No signatures were rewritten and no # noqa comments were added; none of the flagged defaults is genuinely mutable (Form(default_factory=list) builds a new list per request).

ruff check . --select B008 is now clean, and the overall ruff check . count drops from 142 to 124 — exactly those 18. A new tests/test_lint_config.py runs ruff check src --select B008 so the setting can't silently regress (it skips if ruff isn't installed).

This pull request was written by an AI agent (Claude Opus).

Testing

  • pytest tests passes
  • ruff check . passes
  • Added/updated tests for the behavior change

pytest tests: 1909 passed locally on Windows with 18 deselected — those 18 fail identically on main without this change (Windows-only signal/path behaviour and the optional mermaid bundle), so CI on Linux should be green. ruff check . still reports the pre-existing, non-blocking backlog (124 findings, none B008), so that box is left unticked.

Co-authored-by: gitranks[bot] <198371943+gitranks[bot]@users.noreply.github.com>
@onetwothird
onetwothird requested a review from vsn411 as a code owner November 21, 2026 05:46
@vsn411

vsn411 commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks, and welcome! I checked this with ruff 0.17.6. Without the config there are exactly the 18 B008 findings (16 typer.Option, 2 Form), and with it there are none. The typer.Argument, Depends and Query usages don't trigger the rule today, so listing only these two calls is what the issue asked for. Keeping the Form(default_factory=list) reasoning in the description was helpful too.

No changes needed from my side. I've approved the CI run, and once it's green this is ready to merge.

@vsn411
vsn411 merged commit 5dff5e1 into secfoo-com:main Nov 21, 2026
7 checks passed
@github-actions

Copy link
Copy Markdown

Leaderboard update

onetwothird now has 3 points (rank #13). 22 more to reach Bronze.

Full leaderboard

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.

Lint: silence B008 false positives for typer.Option / FastAPI Depends via ruff config

2 participants