MAINT Enable low-hanging ruff rules: A, ERA, EXE, FA, FLY, ICN, ISC, LOG, PLE, Q, RSE, SLOT#1412
Conversation
There was a problem hiding this comment.
Pull request overview
This maintenance PR enables 12 additional ruff linting rule categories to improve code quality and consistency across the PyRIT codebase. The PR applies a combination of auto-fixes and manual noqa annotations where violations are intentional or necessary.
Changes:
- Enabled 12 new ruff rule categories (A, ERA, EXE, FA, FLY, ICN, ISC, LOG, PLE, Q, RSE, SLOT) in pyproject.toml
- Applied auto-fixes for implicit string concatenation (ISC), raise statement formatting (RSE), and import conventions (ICN: numpy → np)
- Added noqa annotations for intentional builtin shadowing (A: id, hash, format, dir parameters), commented documentation code (ERA), and specific edge cases (PLE0704, LOG014)
- Fixed logging calls to use module-level logger instead of root logger (LOG)
Reviewed changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Added 12 new ruff rule categories to linting configuration and updated ignore patterns |
| tests/unit/target/test_http_target.py | Fixed implicit string concatenation in HTTP request string |
| tests/unit/score/test_self_ask_true_false.py | Added ERA001 noqa for legitimate documentation comment |
| tests/unit/score/test_scorer.py | Added ERA001 noqa for legitimate documentation comments about future implementation |
| tests/unit/models/test_seed.py | Renamed id variable to group_id to avoid shadowing builtin |
| tests/unit/models/test_message_piece.py | Renamed sorted variable to sorted_pieces to avoid shadowing builtin |
| tests/unit/mocks.py | Added A002 noqa for intentional id parameter name |
| tests/unit/exceptions/test_exceptions.py | Removed unnecessary parentheses from raise statements |
| tests/unit/converter/test_transparency_attack_converter.py | Changed numpy import to use standard np alias |
| tests/unit/converter/test_selective_text_converter.py | Added ERA001 noqa for base64 encoding documentation comments |
| tests/unit/converter/test_math_obfuscation_converter.py | Added ERA001 noqa for documentation comment |
| tests/unit/converter/test_image_compression_converter.py | Added A002 noqa for format parameter |
| tests/unit/converter/test_ansi_attack_converter.py | Added ERA001 noqa for documentation comment |
| tests/integration/targets/test_targets_and_secrets.py | Added ERA001 noqa for commented-out test configuration |
| tests/integration/targets/test_openai_responses_gpt5.py | Removed commented-out import statements |
| tests/integration/mocks.py | Added A002/A003 noqa for id parameter and attribute |
| pyrit/ui/rpc_client.py | Removed unnecessary parentheses from raise statement |
| pyrit/ui/rpc.py | Removed unnecessary parentheses from raise statements |
| pyrit/score/scorer_evaluation/scorer_metrics_io.py | Added A002 noqa for hash parameter |
| pyrit/score/scorer.py | Removed unnecessary parentheses from raise statements |
| pyrit/scenario/scenarios/airt/psychosocial_scenario.py | Changed to use module logger instead of root logger |
| pyrit/prompt_target/rpc_client.py | Removed unnecessary parentheses from raise statement |
| pyrit/prompt_target/openai/openai_target.py | Removed unnecessary parentheses from raise statements |
| pyrit/prompt_target/hugging_face/hugging_face_chat_target.py | Removed unnecessary parentheses from raise statement |
| pyrit/prompt_target/crucible_target.py | Removed unnecessary parentheses from raise statement |
| pyrit/prompt_target/azure_ml_chat_target.py | Fixed raise statement and implicit string concatenation |
| pyrit/prompt_target/azure_blob_storage_target.py | Fixed implicit string concatenation in error message |
| pyrit/prompt_converter/transparency_attack_converter.py | Changed numpy import to use standard np alias and updated all references |
| pyrit/prompt_converter/insert_punctuation_converter.py | Renamed loop variable from str to char to avoid shadowing builtin |
| pyrit/prompt_converter/azure_speech_text_to_audio_converter.py | Fixed implicit string concatenation in error messages |
| pyrit/prompt_converter/azure_speech_audio_to_text_converter.py | Fixed implicit string concatenation in error messages |
| pyrit/models/storage_io.py | Fixed implicit string concatenation in error message |
| pyrit/models/seeds/seed.py | Changed to use module logger instead of root logger |
| pyrit/models/score.py | Added A002 noqa for id parameter |
| pyrit/models/scenario_result.py | Added A002 noqa for id parameter |
| pyrit/models/message_piece.py | Added A002 noqa for id parameter |
| pyrit/memory/memory_interface.py | Changed to use module logger instead of root logger |
| pyrit/exceptions/exceptions_helpers.py | Added ERA001 noqa for format documentation comment |
| pyrit/exceptions/exception_classes.py | Added PLE0704 noqa for intentional bare raise |
| pyrit/common/path.py | Added A002 noqa for dir parameter |
| pyrit/backend/middleware/error_handlers.py | Added LOG014 noqa for intentional exc_info usage |
| pyrit/auth/azure_auth.py | Fixed implicit string concatenation in error messages |
…LE, Q, RSE, SLOT Enable 12 additional ruff rule categories with zero or few violations: - A: builtin shadowing (noqa for intentional id/hash/format/dir params) - ERA: commented-out code (noqa for legitimate doc comments) - EXE: executable checks (0 violations) - FA: future annotations (0 violations) - FLY: string formatting (0 violations) - ICN: import conventions (numpy -> np) - ISC: implicit string concatenation (auto-fixed) - LOG: logging best practices (use module logger, not root) - PLE: pylint errors (noqa for bare raise in helper) - Q: quotes (0 violations) - RSE: raise statements (auto-fixed unnecessary parens) - SLOT: slot violations (0 violations) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ntication (Azure#1404) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fba26f6 to
2317bf4
Compare
…nging # Conflicts: # pyproject.toml
…ve obsolete ignores, E731 - Use logger.exception() instead of logger.error(exc_info=True) in error_handlers.py - Add missing space between f-strings in azure_speech_text_to_audio_converter.py - Remove obsolete auxiliary_attacks/ui per-file-ignores (issue Azure#1176 completed) - Fix E731 lambda in test_airt_targets_initializer.py - Update doc/ per-file-ignores comment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add per-file-ignores for auxiliary_attacks/ (vendored GCG code) - Expand doc/ ignores to cover A, E712, E722, LOG015 - Simplify ui/ ignores to use broad D prefix - Fix ISC004 (implicit string concatenation) in 5 files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nging # Conflicts: # pyproject.toml # pyrit/prompt_target/azure_ml_chat_target.py
…eption Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nging # Conflicts: # pyproject.toml
Notebook .py files (jupytext) trigger false positives for: - ERA001: jupytext markdown cells look like commented-out code - PLE1142: top-level await is valid in Jupyter notebooks - A: notebook code commonly uses builtins like id, dir, display - LOG: notebooks use root logger for convenience This fixes 880 ruff errors reported on pre-commit run --all-files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 47 out of 47 changed files in this pull request and generated 1 comment.
You can also share your feedback on Copilot code review. Take the survey.
…xception The bare raise would fail with 'No active exception to reraise' when called outside an except block (e.g., from _handle_content_filter_response). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 47 out of 47 changed files in this pull request and generated no new comments.
You can also share your feedback on Copilot code review. Take the survey.
…nging # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
…eption The bare raise is only reachable from except blocks in practice, so the original behavior of re-raising the caller's exception is correct and preserves the exception type for downstream handlers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Enable 12 additional ruff rule categories with zero or few violations:
Description
Tests and Documentation