Skip to content

Ruff config missing mutable-default checks (B006, B008, B039, RUF012) #1054

@enyst

Description

@enyst

Context:
A recent review thread discussed avoiding mutable defaults for the Conversation visualizer parameter. Our Ruff configuration on main does not currently enable rules that catch mutable defaults and related pitfalls.

Proposed Ruff rules to enable:

  • B006 (mutable-argument-default)
  • B008 (function-call-in-default-argument)
  • B039 (mutable-contextvar-default)
  • RUF012 (mutable-class-default)

Current state:

  • pyproject.toml only selects: E, F, I, UP, ARG
  • pre-commit runs ruff check with project config
  • CI runs pre-commit; no additional ruff rules enabled

Quick local run on main with these rules:

  • 20× B008 (function call in default argument)
  • 8× RUF012 (mutable class default)
  • 2× B006 (mutable argument default)
  • 0× B039 (mutable ContextVar default)

Impact:
Enabling these will enforce best practices around default values and prevent subtle shared-state bugs.

Plan:

  1. Add these rules via extend-select in pyproject.toml
  2. Land the config, then follow-up PRs to fix violations (or selectively allowlist safe patterns using extend-immutable-calls for B006/B008 where appropriate)

PR:
A PR enabling these rules has been prepared.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions