Skip to content

MAINT: Standardize deprecation calls and removed_in format#1817

Merged
romanlutz merged 8 commits into
mainfrom
copilot/standardize-deprecation-calls
May 27, 2026
Merged

MAINT: Standardize deprecation calls and removed_in format#1817
romanlutz merged 8 commits into
mainfrom
copilot/standardize-deprecation-calls

Conversation

@romanlutz
Copy link
Copy Markdown
Contributor

Summary

Two related cleanup tasks across the PyRIT codebase, both guided by the "Deprecations" section of .github/instructions/style-guide.instructions.md.

Task 1 — convert warnings.warn(..., DeprecationWarning, ...)print_deprecation_message (15 sites across 9 files)

The style guide mandates pyrit.common.deprecation.print_deprecation_message (never warnings.warn directly) for deprecations of public API. Converted:

File Sites
pyrit/datasets/seed_datasets/seed_dataset_provider.py 3
pyrit/prompt_target/common/prompt_chat_target.py 2
pyrit/prompt_target/azure_ml_chat_target.py 1
pyrit/prompt_target/openai/openai_image_target.py 3
pyrit/prompt_converter/azure_speech_audio_to_text_converter.py 2
pyrit/prompt_converter/azure_speech_text_to_audio_converter.py 1
pyrit/prompt_converter/persuasion_converter.py 1
pyrit/prompt_converter/variation_converter.py 1
pyrit/score/audio_transcript_scorer.py 1

Each conversion preserves the removed_in version the original message advertised. Unused import warnings lines were dropped after conversion.

Non-deprecation warnings.warn sites (UserWarning, FutureWarning, suppression context managers) were intentionally left alone.

Task 2 — strip the v prefix from removed_in= (3 sites)

Style-guide format is "0.15.0", not "v0.15.0".

  • pyrit/setup/initializers/__init__.py
  • pyrit/setup/initializers/pyrit_initializer.py
  • pyrit/prompt_target/hugging_face/hugging_face_endpoint_target.py (also converted from warnings.warn per Task 1's spirit)

Task 3 (audit-driven) — normalize removed_in="2.0""0.16.0" (12 sites)

grep audit surfaced 12 print_deprecation_message calls in pyrit/output/ that all set removed_in="2.0" — a placeholder from the printer-refactor PR (#1732). Per the +2-minor-versions rule and the current 0.14.0.dev0 version, normalized all 12 to "0.16.0":

  • pyrit/output/scorer/base.py (2)
  • pyrit/output/scenario_result/pretty.py (1)
  • pyrit/output/scenario_result/base.py (1)
  • pyrit/output/attack_result/pretty.py (5)
  • pyrit/output/attack_result/markdown.py (3)

One intentional outlier was left alone: pyrit/scenario/core/scenario_strategy.py uses removed_in="0.18.0" with an in-code comment explaining the extended window for Foundry callers.

Test updates (4 files)

A few test assertions checked unique phrasing from the original warnings.warn messages that the helper format doesn't reproduce verbatim. Updated:

  • tests/unit/datasets/test_seed_dataset_provider.py — 2 patterns
  • tests/unit/setup/test_pyrit_initializer.py — 2 patterns (dropped v from regex)
  • tests/unit/prompt_target/target/test_image_target.py — 4 patterns (dropped v, adjusted quoting around style)
  • tests/unit/prompt_target/target/test_normalize_async_integration.py — 1 pattern (message_normalizer is deprecatedmessage_normalizer + deprecated checked separately, to accommodate the helper's (param=...) suffix)
  • tests/unit/prompt_converter/test_azure_speech_text_converter.py — 1 pattern (recognize_audio() does not support callable token providersrecognize_audio + deprecated)

Verification

  • uv run pytest tests/unit -x -q8049 passed, 118 skipped
  • uv run pre-commit run --all-files → all hooks pass (ruff format / ruff check / ty)
  • grep "warnings\.warn.*DeprecationWarning" pyrit/ → zero hits outside pyrit/common/deprecation.py (the helper itself)
  • grep 'removed_in="v' pyrit/ → zero hits
  • grep 'removed_in="2\.0"' pyrit/ → zero hits

romanlutz and others added 3 commits May 26, 2026 15:54
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…eprecation-calls

# Conflicts:
#	pyrit/prompt_target/common/prompt_chat_target.py
The unit-test-diff-cover check failed because six newly-added

print_deprecation_message(...) lines were not exercised by existing tests:

- pyrit/output/scenario_result/base.py:38 (print_summary_async)

- pyrit/output/scorer/base.py:68 (print_objective_scorer), :79 (print_harm_scorer)

- pyrit/prompt_converter/persuasion_converter.py:132 (send_persuasion_prompt_async)

- pyrit/prompt_converter/variation_converter.py:116 (send_variation_prompt_async)

- pyrit/prompt_target/common/prompt_chat_target.py:53 (__init__)

Add focused tests that invoke each shim, assert a DeprecationWarning is

emitted, and verify the shim delegates to the replacement API.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread tests/unit/output/scenario_result/test_base.py Fixed
Comment thread tests/unit/output/scorer/test_base.py Fixed
Comment thread pyrit/score/audio_transcript_scorer.py Outdated
Comment thread pyrit/prompt_target/azure_ml_chat_target.py Outdated
romanlutz and others added 2 commits May 27, 2026 13:32
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…calls' into copilot/standardize-deprecation-calls
@romanlutz romanlutz added this pull request to the merge queue May 27, 2026
Merged via the queue into main with commit 8f3a76c May 27, 2026
50 checks passed
@romanlutz romanlutz deleted the copilot/standardize-deprecation-calls branch May 27, 2026 21:11
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.

2 participants