Skip to content

Commit b9245af

Browse files
romanlutzCopilot
andcommitted
MAINT: Standardize deprecation calls and removed_in format
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f3e012d commit b9245af

22 files changed

Lines changed: 124 additions & 122 deletions

pyrit/datasets/seed_datasets/seed_dataset_provider.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import asyncio
55
import inspect
66
import logging
7-
import warnings
87
from abc import ABC, abstractmethod
98
from dataclasses import fields as dc_fields
109
from typing import Any, Optional
1110

1211
from tqdm import tqdm
1312

13+
from pyrit.common.deprecation import print_deprecation_message
1414
from pyrit.datasets.seed_datasets.seed_metadata import SeedDatasetFilter, SeedDatasetLoadTime, SeedDatasetMetadata
1515
from pyrit.models.seeds import SeedDataset
1616

@@ -50,12 +50,10 @@ def __init_subclass__(cls, **kwargs: Any) -> None:
5050
cls.fetch_dataset is not SeedDatasetProvider.fetch_dataset
5151
and cls.fetch_dataset_async is SeedDatasetProvider.fetch_dataset_async
5252
):
53-
warnings.warn(
54-
f"{cls.__name__} overrides the deprecated fetch_dataset method. "
55-
"Rename the override to fetch_dataset_async; fetch_dataset will be "
56-
"removed in v0.16.0.",
57-
DeprecationWarning,
58-
stacklevel=2,
53+
print_deprecation_message(
54+
old_item=f"{cls.__name__}.fetch_dataset",
55+
new_item=f"{cls.__name__}.fetch_dataset_async",
56+
removed_in="0.16.0",
5957
)
6058
if not inspect.isabstract(cls) and getattr(cls, "should_register", True):
6159
SeedDatasetProvider._registry[cls.__name__] = cls
@@ -95,11 +93,10 @@ async def fetch_dataset_async(self, *, cache: bool = True) -> SeedDataset:
9593
cls = type(self)
9694
if cls.fetch_dataset is SeedDatasetProvider.fetch_dataset:
9795
raise NotImplementedError(f"{cls.__name__} must implement fetch_dataset_async.")
98-
warnings.warn(
99-
f"{cls.__name__}.fetch_dataset is deprecated and will be removed in v0.16.0; "
100-
"rename the override to fetch_dataset_async.",
101-
DeprecationWarning,
102-
stacklevel=2,
96+
print_deprecation_message(
97+
old_item=f"{cls.__name__}.fetch_dataset",
98+
new_item=f"{cls.__name__}.fetch_dataset_async",
99+
removed_in="0.16.0",
103100
)
104101
return await self.fetch_dataset(cache=cache)
105102

@@ -116,11 +113,10 @@ async def fetch_dataset(self, *, cache: bool = True) -> SeedDataset:
116113
Returns:
117114
SeedDataset: The fetched dataset with prompts.
118115
"""
119-
warnings.warn(
120-
"SeedDatasetProvider.fetch_dataset is deprecated and will be removed in v0.16.0; "
121-
"use fetch_dataset_async instead.",
122-
DeprecationWarning,
123-
stacklevel=2,
116+
print_deprecation_message(
117+
old_item="SeedDatasetProvider.fetch_dataset",
118+
new_item="SeedDatasetProvider.fetch_dataset_async",
119+
removed_in="0.16.0",
124120
)
125121
return await self.fetch_dataset_async(cache=cache)
126122

pyrit/output/attack_result/markdown.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async def print_result_async(
132132
include_adversarial_conversation: bool = False,
133133
) -> None:
134134
"""Use ``write_async`` instead. This method is deprecated."""
135-
print_deprecation_message(old_item="print_result_async", new_item="write_async", removed_in="2.0")
135+
print_deprecation_message(old_item="print_result_async", new_item="write_async", removed_in="0.16.0")
136136
await self.write_async(
137137
result,
138138
include_auxiliary_scores=include_auxiliary_scores,
@@ -142,13 +142,13 @@ async def print_result_async(
142142

143143
async def output_conversation_async(self, result: AttackResult, *, include_scores: bool = False) -> None:
144144
"""Use ``write_async`` instead. This method is deprecated."""
145-
print_deprecation_message(old_item="output_conversation_async", new_item="write_async", removed_in="2.0")
145+
print_deprecation_message(old_item="output_conversation_async", new_item="write_async", removed_in="0.16.0")
146146
lines = await self._get_conversation_markdown_async(result=result, include_scores=include_scores)
147147
await self._write_async("\n".join(lines))
148148

149149
async def print_summary_async(self, result: AttackResult) -> None:
150150
"""Use ``write_async`` instead. This method is deprecated."""
151-
print_deprecation_message(old_item="print_summary_async", new_item="write_async", removed_in="2.0")
151+
print_deprecation_message(old_item="print_summary_async", new_item="write_async", removed_in="0.16.0")
152152
markdown_lines = await self._get_summary_markdown_async(result)
153153
await self._write_async("\n".join(markdown_lines))
154154

pyrit/output/attack_result/pretty.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async def print_result_async(
129129
include_adversarial_conversation: bool = False,
130130
) -> None:
131131
"""Use ``write_async`` instead. This method is deprecated."""
132-
print_deprecation_message(old_item="print_result_async", new_item="write_async", removed_in="2.0")
132+
print_deprecation_message(old_item="print_result_async", new_item="write_async", removed_in="0.16.0")
133133
await self.write_async(
134134
result,
135135
include_auxiliary_scores=include_auxiliary_scores,
@@ -171,7 +171,7 @@ async def print_conversation_async(
171171
self, result: AttackResult, *, include_scores: bool = False, include_reasoning_trace: bool = False
172172
) -> None:
173173
"""Use ``write_async`` instead. This method is deprecated."""
174-
print_deprecation_message(old_item="print_conversation_async", new_item="write_async", removed_in="2.0")
174+
print_deprecation_message(old_item="print_conversation_async", new_item="write_async", removed_in="0.16.0")
175175
content = await self._render_conversation_async(
176176
result, include_scores=include_scores, include_reasoning_trace=include_reasoning_trace
177177
)
@@ -181,7 +181,7 @@ async def output_conversation_async(
181181
self, result: AttackResult, *, include_scores: bool = False, include_reasoning_trace: bool = False
182182
) -> None:
183183
"""Use ``write_async`` instead. This method is deprecated."""
184-
print_deprecation_message(old_item="output_conversation_async", new_item="write_async", removed_in="2.0")
184+
print_deprecation_message(old_item="output_conversation_async", new_item="write_async", removed_in="0.16.0")
185185
content = await self._render_conversation_async(
186186
result, include_scores=include_scores, include_reasoning_trace=include_reasoning_trace
187187
)
@@ -195,7 +195,7 @@ async def print_messages_async(
195195
include_reasoning_trace: bool = False,
196196
) -> None:
197197
"""Use the conversation printer's ``write_async`` instead. This method is deprecated."""
198-
print_deprecation_message(old_item="print_messages_async", new_item="write_async", removed_in="2.0")
198+
print_deprecation_message(old_item="print_messages_async", new_item="write_async", removed_in="0.16.0")
199199
content = await self._conversation_printer.render_async(
200200
messages, include_scores=include_scores, include_reasoning_trace=include_reasoning_trace
201201
)
@@ -256,7 +256,7 @@ async def _render_summary_async(self, result: AttackResult) -> str:
256256

257257
async def print_summary_async(self, result: AttackResult) -> None:
258258
"""Use ``write_async`` instead. This method is deprecated."""
259-
print_deprecation_message(old_item="print_summary_async", new_item="write_async", removed_in="2.0")
259+
print_deprecation_message(old_item="print_summary_async", new_item="write_async", removed_in="0.16.0")
260260
content = await self._render_summary_async(result)
261261
await self._write_async(content)
262262

pyrit/output/scenario_result/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ async def print_summary_async(self, result: ScenarioResult) -> None:
3535
Args:
3636
result (ScenarioResult): The scenario result to summarize.
3737
"""
38-
print_deprecation_message(old_item="print_summary_async", new_item="write_async", removed_in="2.0")
38+
print_deprecation_message(old_item="print_summary_async", new_item="write_async", removed_in="0.16.0")
3939
await self.write_async(result)

pyrit/output/scenario_result/pretty.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ async def print_summary_async(self, result: ScenarioResult) -> None:
251251
Args:
252252
result (ScenarioResult): The scenario result to summarize.
253253
"""
254-
print_deprecation_message(old_item="print_summary_async", new_item="write_async", removed_in="2.0")
254+
print_deprecation_message(old_item="print_summary_async", new_item="write_async", removed_in="0.16.0")
255255
await self.write_async(result)
256256

257257

pyrit/output/scorer/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def print_objective_scorer(self, *, scorer_identifier: ComponentIdentifier
6565
Args:
6666
scorer_identifier (ComponentIdentifier): The scorer identifier.
6767
"""
68-
print_deprecation_message(old_item="print_objective_scorer", new_item="write_async", removed_in="2.0")
68+
print_deprecation_message(old_item="print_objective_scorer", new_item="write_async", removed_in="0.16.0")
6969
await self.write_async(scorer_identifier=scorer_identifier)
7070

7171
async def print_harm_scorer(self, *, scorer_identifier: ComponentIdentifier, harm_category: str) -> None:
@@ -76,5 +76,5 @@ async def print_harm_scorer(self, *, scorer_identifier: ComponentIdentifier, har
7676
scorer_identifier (ComponentIdentifier): The scorer identifier.
7777
harm_category (str): The harm category.
7878
"""
79-
print_deprecation_message(old_item="print_harm_scorer", new_item="write_async", removed_in="2.0")
79+
print_deprecation_message(old_item="print_harm_scorer", new_item="write_async", removed_in="0.16.0")
8080
await self.write_async(scorer_identifier=scorer_identifier, harm_category=harm_category)

pyrit/prompt_converter/azure_speech_audio_to_text_converter.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import logging
55
import time
6-
import warnings
76
from collections.abc import Awaitable, Callable
87
from typing import TYPE_CHECKING, Any, Optional
98

@@ -12,6 +11,7 @@
1211

1312
from pyrit.auth.azure_auth import get_speech_config, get_speech_config_async
1413
from pyrit.common import default_values
14+
from pyrit.common.deprecation import print_deprecation_message
1515
from pyrit.identifiers import ComponentIdentifier
1616
from pyrit.models import PromptDataType, data_serializer_factory
1717
from pyrit.prompt_converter.prompt_converter import ConverterResult, PromptConverter
@@ -76,12 +76,14 @@ def __init__(
7676
ValueError: If the required environment variables or parameters are not set.
7777
"""
7878
if use_entra_auth is not None:
79-
warnings.warn(
80-
"'use_entra_auth' is deprecated and will be removed in v0.15.0. "
81-
"Authentication is now auto-detected: pass a key string for key auth, "
82-
"a callable token provider for token auth, or omit for automatic Entra ID auth.",
83-
DeprecationWarning,
84-
stacklevel=2,
79+
print_deprecation_message(
80+
old_item="AzureSpeechAudioToTextConverter(use_entra_auth=...)",
81+
new_item=(
82+
"AzureSpeechAudioToTextConverter(...) with automatic auth detection: "
83+
"pass a key string for key auth, a callable token provider for token auth, "
84+
"or omit for automatic Entra ID auth"
85+
),
86+
removed_in="0.15.0",
8587
)
8688

8789
self._azure_speech_region: str = default_values.get_required_value(
@@ -189,11 +191,10 @@ def recognize_audio(self, audio_bytes: bytes) -> str:
189191
ModuleNotFoundError: If the azure.cognitiveservices.speech module is not installed.
190192
"""
191193
if self._token_provider:
192-
warnings.warn(
193-
"recognize_audio() does not support callable token providers. "
194-
"Use convert_async() instead, which correctly resolves token providers.",
195-
DeprecationWarning,
196-
stacklevel=2,
194+
print_deprecation_message(
195+
old_item="AzureSpeechAudioToTextConverter.recognize_audio",
196+
new_item="AzureSpeechAudioToTextConverter.convert_async",
197+
removed_in="0.15.0",
197198
)
198199
speech_config = get_speech_config(
199200
resource_id=self._azure_speech_resource_id,

pyrit/prompt_converter/azure_speech_text_to_audio_converter.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Licensed under the MIT license.
33

44
import logging
5-
import warnings
65
from collections.abc import Awaitable, Callable
76
from typing import TYPE_CHECKING, Literal, Optional
87

@@ -11,6 +10,7 @@
1110

1211
from pyrit.auth.azure_auth import get_speech_config_async
1312
from pyrit.common import default_values
13+
from pyrit.common.deprecation import print_deprecation_message
1414
from pyrit.identifiers import ComponentIdentifier
1515
from pyrit.models import PromptDataType, data_serializer_factory
1616
from pyrit.prompt_converter.prompt_converter import ConverterResult, PromptConverter
@@ -82,12 +82,14 @@ def __init__(
8282
ValueError: If the required environment variables or parameters are not set.
8383
"""
8484
if use_entra_auth is not None:
85-
warnings.warn(
86-
"'use_entra_auth' is deprecated and will be removed in v0.15.0. "
87-
"Authentication is now auto-detected: pass a key string for key auth, "
88-
"a callable token provider for token auth, or omit for automatic Entra ID auth.",
89-
DeprecationWarning,
90-
stacklevel=2,
85+
print_deprecation_message(
86+
old_item="AzureSpeechTextToAudioConverter(use_entra_auth=...)",
87+
new_item=(
88+
"AzureSpeechTextToAudioConverter(...) with automatic auth detection: "
89+
"pass a key string for key auth, a callable token provider for token auth, "
90+
"or omit for automatic Entra ID auth"
91+
),
92+
removed_in="0.15.0",
9193
)
9294

9395
self._azure_speech_region: str = default_values.get_required_value(

pyrit/prompt_converter/persuasion_converter.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import json
55
import logging
66
import pathlib
7-
import warnings
87

98
from pyrit.common.apply_defaults import REQUIRED_VALUE, apply_defaults
9+
from pyrit.common.deprecation import print_deprecation_message
1010
from pyrit.common.path import CONVERTER_SEED_PROMPT_PATH
1111
from pyrit.exceptions import (
1212
InvalidJsonException,
@@ -129,10 +129,9 @@ async def send_persuasion_prompt_async(self, request: Message) -> str:
129129
Returns:
130130
str: The post-processed response text.
131131
"""
132-
warnings.warn(
133-
"send_persuasion_prompt_async is deprecated; the converter now uses the unified "
134-
"_send_with_retries_async helper from LLMGenericTextConverter.",
135-
DeprecationWarning,
136-
stacklevel=2,
132+
print_deprecation_message(
133+
old_item="PersuasionConverter.send_persuasion_prompt_async",
134+
new_item="PersuasionConverter._send_with_retries_async (inherited from LLMGenericTextConverter)",
135+
removed_in="0.16.0",
137136
)
138137
return await self._send_with_retries_async(request)

pyrit/prompt_converter/variation_converter.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import json
55
import logging
66
import pathlib
7-
import warnings
87

98
from pyrit.common.apply_defaults import REQUIRED_VALUE, apply_defaults
9+
from pyrit.common.deprecation import print_deprecation_message
1010
from pyrit.common.path import CONVERTER_SEED_PROMPT_PATH
1111
from pyrit.exceptions import (
1212
InvalidJsonException,
@@ -113,10 +113,9 @@ async def send_variation_prompt_async(self, request: Message) -> str:
113113
Returns:
114114
str: The post-processed response text.
115115
"""
116-
warnings.warn(
117-
"send_variation_prompt_async is deprecated; the converter now uses the unified "
118-
"_send_with_retries_async helper from LLMGenericTextConverter.",
119-
DeprecationWarning,
120-
stacklevel=2,
116+
print_deprecation_message(
117+
old_item="VariationConverter.send_variation_prompt_async",
118+
new_item="VariationConverter._send_with_retries_async (inherited from LLMGenericTextConverter)",
119+
removed_in="0.16.0",
121120
)
122121
return await self._send_with_retries_async(request)

0 commit comments

Comments
 (0)