[MAINT]: Enable ruff preview#55
Open
spencrr wants to merge 16 commits into
Open
Conversation
1d06f03 to
6ac60be
Compare
6ac60be to
8023cd4
Compare
- 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.
289c969 to
c1d92e5
Compare
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
Align RAMPART's lint configuration with sibling project PyRIT by enabling ruff preview mode and burning down the global
ignorelist it surfaces. After this PR, the project lints clean under preview with no broad rule suppressions — onlyDOC502(intentional) andRUF076(autouse-fixture carve-out) remain inextend-ignore.Tooling
pyproject.toml:[tool.ruff.lint]gainspreview = true.extend-ignorereduced to two rules (each with rationale). Per-file ignores fortests/**extended to coverDOC201,DOC501,PLC1901,PLC2701.0.15.10→0.15.17(project + pre-commit hook).typing-extensions>=4.12; python_version < '3.12'runtime dep, sourcingtyping.override(PEP 698) under Python 3.11.Public API factory restructure
Three top-level factory classes moved out of init.py into private modules so the package init files become thin re-export shims (resolves preview rules pushing logic out of init.py):
Attacksrampart/attacks/__init__.pyProbesrampart/probes/__init__.pyPayloadsrampart/payloads/__init__.pyPublic import paths (
from rampart.attacks import Attacks, etc.) and__all__are unchanged.Docstrings: Returns / Raises documented on public APIs
DOC201/DOC501(preview) require explicitReturns:andRaises:sections where applicable. Coverage added across:Code cleanups surfaced by preview
@staticmethodon private helpers with noselfuse (PLR6301):_xpia._adjust_for_observability,_generator._build_user_message,json_file._serialize_turn.@overrideannotation on the pytest plugin'sResultCollectionHandler.on_eventwith asys.version_info >= (3, 12)fallback totyping_extensions.overridefor Python 3.11 (rampart/pytest_plugin/_collection.py).open(path) … f.read()→Path(path).read_text(...)(PTH123); tuple membership → set literal (PLR6201);pytest.mark.__getattr__(name)→getattr(pytest.mark, name)(B009).raise X(msg,)spanning multiple lines to single-lineraise X(msg)(UP034/formatter preference).RUF029(async with noawait) — dropasyncfrom sync test callbacks (tests/unit/payloads/test_generator.py,test_payloads.py,tests/unit/core/test_execution.py);pytest.approx(...)adopted for float equality acrosstest_result.py, test_types.py, test_llm_judge.py,test_llm_bridge.py, test_plugin.py. Trailing blank lines removed from package init.py files (W391).# noqa: BLE001in _session.py, plugin.py,core/execution.py(preview no longer flags the surrounding code).Breaking changes
None. Public imports (
Attacks,Probes,Payloads,XPIAExecution,SingleTurnExecution,PayloadStore,PayloadTemplate) and their signatures are unchanged.Checklist
pre-commit run --all-filespasses