Upgrade ruff from v0.1.3 to v0.15.15 in pre-commit

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      Upgrade ruff in .pre-commit-config.yaml and the local synchro hook from v0.1.3 to v0.15.15.

      The version jump spans ~14 minor releases. Three root causes of errors after upgrading:

      1. New rules in already-selected rule sets
      The config selects broad rule set categories (UP, RUF, SIM, B, ASYNC, PT, etc.). Ruff ships new rules in nearly every release, and all are automatically active. Every new rule that fires on existing code is a new error.

      2. Stale ignore entries
      Some ignored rule codes no longer exist (e.g. PT004 was deprecated and removed in 0.2.x). Newer ruff versions warn or error on unknown rule codes in the ignore list.

      3. Formatter drift (ruff-format)
      The formatter's opinions on whitespace, trailing commas, and string quoting have evolved over 14 versions, causing widespread cosmetic reformatting across bson/, pymongo/, and gridfs/.

      Definition of done

      • Run ruff check --statistics to identify the highest-frequency new rule violations and decide what to fix vs. ignore
      • Audit ignore list in pyproject.toml for stale/removed rule codes (e.g. PT004)
      • Commit formatter-only changes (ruff-format) separately from logic/lint fixes to keep the diff reviewable
      • Update both the astral-sh/ruff-pre-commit rev and the synchro hook's additional_dependencies pin

      Pitfalls

      • Stale ignore entries — some rule codes in pyproject.toml no longer exist in newer ruff (e.g. PT004 was removed in 0.2.x). Newer ruff treats unknown rule codes as errors, so the ignore list needs to be audited before anything else or the linter won't even run cleanly.
      • Formatter churn obscures real fixes — ruff-format will touch hundreds of lines across bson/, pymongo/, and gridfs/. If formatter changes are mixed with lint fixes in one commit, the diff becomes unreviable. Do the formatter pass first as a standalone commit.
      • synchro hook must stay in sync — the additional_dependencies pin in the local synchro hook (ruff==0.15.15) must match the astral-sh/ruff-pre-commit rev exactly, or the two hooks may produce different results and fight each other.
      • Auto-fix can make wrong changes — --fix is enabled in the hook args. Some rules' auto-fixes are semantically meaningful (not just style), so blindly applying all fixes without reviewing could introduce subtle bugs. Run --fix rule-set by rule-set rather than all at once.
      • isort.required-imports side effects — the config enforces from {}future{} import annotations on all files. Newer UP rules interact with this (e.g. rules around Optional, Union, string annotations). Fixes applied without that import present will be wrong; fixes applied after may be redundant with existing # type: ignore comments.
         

       

            Assignee:
            Noah Stapp
            Reporter:
            Alex Clark
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: