[MAINT]: Enable ruff preview and address various linting issues#55
Draft
spencrr wants to merge 13 commits into
Draft
[MAINT]: Enable ruff preview and address various linting issues#55spencrr wants to merge 13 commits into
spencrr wants to merge 13 commits into
Conversation
- Replace bare float == comparisons in tests with pytest.approx(). - Suppress pyright reportUnknownMemberType on the new approx calls (matches existing convention used elsewhere in the suite). - Remove RUF069 from global ruff ignore list.
The five async helpers flagged by RUF029 are sync side_effect callbacks passed to AsyncMock-backed targets. AsyncMock accepts sync side_effects and awaits the return value, so dropping 'async' from the helpers is semantically equivalent. - Drop async from capture_eval / capture helpers in tests. - Remove RUF029 from global ruff ignore list.
- Replace open()/read() with Path.read_text() in the one test helper. - Remove FURB101 from global ruff ignore list.
All 10 violations were in tests, where 'x == ""' asserts an explicit empty-string contract \u2014 rewriting to 'not x' would silently accept None / 0 / [] as well. - Move PLC1901 from global ignore to per-file-ignores[tests/**] with a comment explaining the intent. - Production code remains under PLC1901 enforcement.
Extract logic out of the three package __init__.py files so they contain only docstrings and re-exports: - rampart/attacks/__init__.py -> Attacks class moved to rampart/attacks/_factory.py. - rampart/probes/__init__.py -> Probes class moved to rampart/probes/_factory.py. - rampart/payloads/__init__.py -> Payloads class plus the _apply_converters_async and _build_text_payload helpers moved to rampart/payloads/_facade.py (kept separate from _generator.py so the lower-level generator stays focused on LLM I/O). Public import paths are unchanged (still re-exported via __init__). - Remove RUF067 from global ruff ignore list.
DOC502 forbids documenting exceptions that propagate from a delegated callee. That conflicts with Google-style / Sphinx / numpydoc convention, which deliberately documents such exceptions because they are part of the caller-visible contract. All 4 current sites (KeyError from str.format_map, ValueError from a _validate helper, pytest.UsageError from trial-marker helpers) are legitimate contract exceptions worth documenting. The rule's 'fixes' (delete the Raises: section, or wrap with try/except + re-raise) would degrade the docs or add boilerplate that hides the original error. - Move DOC502 from the TODO ignore list into a separately documented 'intentionally disabled' extend-ignore with rationale.
Ruff format collapses 'raise X(\n msg,\n)' to a single line. These changes were produced by the formatter; no behavioral changes.
Document the Raises: contract for the 10 production functions that raise exceptions but had no Raises: section. Also add DOC501 to the tests/** per-file-ignores: test fixture executions (e.g. one-line _execute_async that just 'raise InfrastructureError(...)') are self-documenting and don't need contract docstrings. Files touched (Raises: sections added): - rampart/core/types.py (Payload.__post_init__, Request.__post_init__, EvalContext.current_turn) - rampart/drivers/llm.py (_ensure_initialized, _assert_conversations_consistent, _send_async) - rampart/payloads/_store.py (_validate_collection_name) - rampart/pyrit_bridge/llm_bridge.py (_validate) - rampart/pytest_plugin/plugin.py (_create_trial_clones) - rampart/surfaces/onedrive.py (InjectionHandle.__aenter__) - Remove DOC501 from global ruff ignore list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Intent is to align with PyRIT (and enable ruff preview rules).
Enables
preview = truefor ruff and burns down the globalignorelist it surfaced. After this PR, the project lints clean under preview with no broad rule suppressions - onlyDOC502(intentional, with rationale) remains.rampart/attacks/,rampart/probes/, andrampart/payloads/__init__.pymodules into thin re-export shims, moving class bodies (Attacks,Probes,Payloads) into dedicated private modules.selfuse to@staticmethod; added an@override-annotated handler in the pytest plugin with a conditionaltyping_extensionsfallback for Python 3.11.asyncfrom sync test callbacks, switched manual file reads toPath.read_text(...), removed unusedasyncin helpers, modernizedpytest.approxusage, and scoped test-only rule carve-outs in[tool.ruff.lint.per-file-ignores].Breaking changes
None.
Checklist
pre-commit run --all-filespasses