Skip to content

MAINT: Migrate AddImage/AddTextImage converter deprecations to print_deprecation_message#1875

Merged
romanlutz merged 5 commits into
microsoft:mainfrom
romanlutz:romanlutz/deprecation-helper-migration
Jun 2, 2026
Merged

MAINT: Migrate AddImage/AddTextImage converter deprecations to print_deprecation_message#1875
romanlutz merged 5 commits into
microsoft:mainfrom
romanlutz:romanlutz/deprecation-helper-migration

Conversation

@romanlutz
Copy link
Copy Markdown
Contributor

Description

The PyRIT style guide (.github/instructions/style-guide.instructions.md, Deprecations section) requires all deprecations to go through pyrit.common.deprecation.print_deprecation_message so the message format and DeprecationWarning filtering stay consistent across the codebase. Three call sites in the prompt-converter package bypassed the helper by emitting FutureWarning directly via warnings.warn. This PR migrates the warning mechanism without resetting the deprecation clock.

Sites migrated

  • pyrit/prompt_converter/add_text_image_converter.py:66 -- positional text_to_add -> keyword
  • pyrit/prompt_converter/add_image_text_converter.py:86 -- positional img_to_add -> keyword
  • pyrit/prompt_converter/add_image_text_converter.py:99 -- x_pos/y_pos -> bounding_box

All three were introduced in #1591 on 2026-04-22, during the 0.14.0.dev0 cycle (after v0.13.0 was tagged). They have not shipped in any release yet, so the originally announced removed_in="0.15.0" is the next still-pending release and is preserved as-is for all three. The two unused import warnings statements were removed since no other warnings.warn calls remain in those files.

Audit context (sites intentionally left alone)

  • pyrit/prompt_target/hugging_face/hugging_face_endpoint_target.py:203 and pyrit/prompt_target/hugging_face/hugging_face_chat_target.py:511 emit a UserWarning when sampling parameters are set without do_sample=True. These are legitimate misconfiguration warnings, not deprecations, so they stay on warnings.warn.
  • pyrit/auxiliary_attacks/__init__.py:20 emits an ExperimentalWarning on package import. The module is experimental, not deprecated, so it stays on warnings.warn.

Tests and Documentation

The warning class changes FutureWarning -> DeprecationWarning as a side effect of using the helper, so the three corresponding pytest.warns(...) assertions and one warnings.simplefilter("error", ...) check in tests/unit/prompt_converter/test_add_image_text_converter.py were updated to match the new class and the helper-generated message text. No JupyText changes -- the deprecation surface is internal to converter construction and not demonstrated in any notebook.

Verified locally:

  • pytest tests/unit/prompt_converter/test_add_text_image_converter.py tests/unit/prompt_converter/test_add_image_text_converter.py -v -- 37 passed
  • pytest tests/unit/prompt_converter/ tests/unit/common/test_deprecation.py -x --timeout=60 -- 981 passed, 37 skipped, 0 failed
  • pre-commit run --files ... -- all hooks pass (ruff format, ruff check, ty)

…deprecation_message

The PyRIT style guide (.github/instructions/style-guide.instructions.md,
Deprecations section) requires all deprecations to go through
pyrit.common.deprecation.print_deprecation_message — never raw
warnings.warn — so message format and DeprecationWarning filtering stay
consistent across the codebase.

Three call sites in the prompt_converter package bypassed the helper by
emitting FutureWarning directly. They are all positional/legacy-kwarg
migrations introduced in commit bde0ed1 (PR microsoft#1591) on 2026-04-22,
during the 0.14.0.dev0 cycle (i.e. after v0.13.0 was tagged). The
originally announced removal version is 0.15.0, which has not yet
shipped to users, so we preserve removed_in="0.15.0" on all three —
this migrates the *mechanism* without resetting the deprecation clock.

Migrated sites:
- pyrit/prompt_converter/add_text_image_converter.py:66
  (positional text_to_add → keyword)
- pyrit/prompt_converter/add_image_text_converter.py:86
  (positional img_to_add → keyword)
- pyrit/prompt_converter/add_image_text_converter.py:99
  (x_pos/y_pos → bounding_box)

The warning class changes FutureWarning → DeprecationWarning as a side
effect of using the helper, so the three corresponding pytest.warns
assertions and the warnings.simplefilter("error", ...) check in
tests/unit/prompt_converter/test_add_image_text_converter.py were
updated to match.

Verified separately: the two warnings.warn(..., UserWarning, ...) calls
in pyrit/prompt_target/hugging_face/{hugging_face_endpoint_target,
hugging_face_chat_target}.py are legitimate user-misconfiguration
warnings about sampling parameters (not deprecations) and were left
untouched, as was the ExperimentalWarning in
pyrit/auxiliary_attacks/__init__.py.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz closed this Jun 1, 2026
@romanlutz romanlutz reopened this Jun 1, 2026
…eprecation-helper-migration

# Conflicts:
#	pyrit/prompt_converter/add_image_text_converter.py
#	pyrit/prompt_converter/add_text_image_converter.py
Comment thread pyrit/prompt_converter/add_text_image_converter.py
romanlutz and others added 2 commits June 1, 2026 16:34
Adds three tests mirroring AddImageTextConverter's positional-arg coverage:
- positional text_to_add emits DeprecationWarning and still works
- positional + keyword raises TypeError
- 2+ positional args raises TypeError

Lifts diff-cover for the merged branch back above the 90% gate.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ValbuenaVC ValbuenaVC enabled auto-merge June 1, 2026 23:40
@ValbuenaVC ValbuenaVC added this pull request to the merge queue Jun 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 1, 2026
@romanlutz romanlutz added this pull request to the merge queue Jun 2, 2026
Merged via the queue into microsoft:main with commit 092126d Jun 2, 2026
48 checks passed
@romanlutz romanlutz deleted the romanlutz/deprecation-helper-migration branch June 2, 2026 00:20
romanlutz added a commit to romanlutz/PyRIT that referenced this pull request Jun 2, 2026
Brings in 3 new commits from main:

- 648faa9 FEAT: Backfill class-level metadata for all remote seed datasets (microsoft#1780)
- 092126d MAINT: Migrate AddImage/AddTextImage converter deprecations to print_deprecation_message (microsoft#1875)
- 376e000 FEAT: Add TatweelConverter for Arabic kashida insertion (microsoft#1869)

Conflict resolution (11 files): took main's version everywhere
(`git checkout --theirs`), then re-ran `ruff check --fix` to
re-apply the PEP 604 sweep to main's new code (~36 violations
auto-fixed). Same hand-fix for the runtime `Optional[dict]` in
`pyrit/models/message_piece.py` PlainSerializer `return_type`
that ruff can't auto-rewrite.

Verification:
- ruff check pyrit/ tests/ doc/ - clean
- ruff format --check - clean
- pytest tests/unit -n 4 - 8977 passed, 5 skipped, 0 failures

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants