Skip to content

chore: adopt ruff's default rules and drop the select pin - #706

Open
hirosassa wants to merge 1 commit into
chore/ruff-autofixfrom
chore/ruff-adopt-defaults
Open

hirosassa wants to merge 1 commit into
chore/ruff-autofixfrom
chore/ruff-adopt-defaults

Conversation

@hirosassa

@hirosassa hirosassa commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #698 (step 3 of the plan in the thread). Stacked on #705.

What

Follows ruff's default rule set (option 1 in #698): drops the select = ["E4", "E7", "E9", "F"] pin added in #693.

  • Manual fixes for what the auto-fix in chore: apply ruff 0.17 default-rule auto-fixes #705 left:
    • PYI036: __exit__ annotations (build.py, worker.py).
    • RUF012: ClassVar for _instances, forward_reporter_attributes and a test task's resources.
    • TC004: import GCSClient / S3Client by name instead of the module, so the optional dependencies stay lazily imported (a false positive of the rule, as noted in the thread).
    • SIM117: merged nested with in tests.
    • SIM115: the open() lambdas in test_target.py became helpers that use with.
    • PIE790: unnecessary pass.
  • ignore list with a WHY comment: BLE001, S110 (the worker and the file processors catch everything on purpose), TRY002, TRY004 (fixing them changes the exception type users see, which belongs to 2.0.0 / 2.0.0 removals #685).

Verification

ruff check, ruff format, pyright (0 errors) and the full pytest suite (873 passed) pass locally.

🤖 Generated with Claude Code

Fix the remaining violations by hand (PYI036, RUF012, TC004, SIM117, SIM115, PIE790) and
ignore BLE001, S110, TRY002 and TRY004, which flag code that is deliberate or whose fix
changes the exception type users see.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@kitagry kitagry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! This matches what we agreed on in #698, and I checked it locally on top of #705 (ruff 0.17.5):

  • ruff check . passes with the default rules, and ruff format --check, pyright (0 errors) and pytest -n auto (873 passed) pass too.
  • The ignore list has exactly the four rules from the thread, with WHY comments, and extend-select (B, I, UP, TID253), B006/B008 and the per-file-ignores are unchanged. No new # noqa.
  • TC004: with from luigi.contrib.s3 import S3Client / from luigi.contrib.gcs import GCSClient inside the functions, the optional dependencies stay lazy. In a clean venv with only pip install . (no s3/gcs extras), import gokart, gokart.s3_config and gokart.gcs_config work on Python 3.11 and 3.14, none of boto3 / google.cloud.storage / googleapiclient / luigi.contrib.s3 / luigi.contrib.gcs is loaded, and S3Config().get_s3_client() still raises the friendly "Install them with: pip install gokart[s3]" error. The tests that patch luigi.contrib.gcs.GCSClient still work because the name is looked up when the function runs.
  • The __exit__ annotations (type[BaseException] | None, BaseException | None, TracebackType | None) are the standard ones, and __enter__ already returns Self after #705.
  • Nothing from #700 is repeated: the ObjectStorage and TaskLockException fixes are already in the base, and this PR does not touch them.

Two nits, both non-blocking:

  1. test/test_build.py:333: resources: ClassVar[...] # pyright: ignore[reportIncompatibleVariableOverride] silences RUF012 by adding a pyright ignore, because luigi declares resources as an instance variable (resources: Dict[str, Any] = {}). Overriding process_resources() (which the worker calls; see gokart/worker.py:967) avoids both the ClassVar and the ignore:
class _NeedsUnavailableResource(gokart.TaskOnKart[int]):
    task_namespace = __name__

    # WHY: luigi treats an unconfigured resource as having 1 unit, so asking for 2 is never satisfiable; the odd name keeps a developer's luigi.cfg out of it
    def process_resources(self) -> dict[str, int]:
        return {'_gokart_test_not_run': 2}

I tried it: ruff, pyright and the test pass. A plain resources = {...} # noqa: RUF012 would also work. Fine to leave as is if you prefer.

  1. gokart/worker.py:592 (and WorkerProtocol.__exit__ in gokart/build.py:91): exc_type / exc_value were renamed, but the third parameter is still traceback, which shadows the import traceback at the top of worker.py (used at lines 453, 461, 676). It is harmless today, but since the signature is being touched anyway, exc_tb would keep someone from calling traceback.format_exc() there later by mistake.

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.

Decide whether to adopt ruff 0.17's expanded default lint rules

2 participants