Skip to content

Commit 8f3a76c

Browse files
romanlutzCopilot
andauthored
MAINT: Standardize deprecation calls and removed_in format (#1817)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ed8f6cf commit 8f3a76c

29 files changed

Lines changed: 318 additions & 134 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: 22 additions & 14 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
@@ -66,8 +66,16 @@ def __init__(
6666
If omitted, Entra ID auth via ``DefaultAzureCredential`` is used automatically.
6767
azure_speech_resource_id (str, Optional): The resource ID for accessing the service when using
6868
Entra ID auth. Required when using a callable token provider or when no API key is available.
69-
use_entra_auth (bool, Optional): **Deprecated.** Will be removed in v0.15.0.
70-
Authentication is now auto-detected from the provided credentials.
69+
use_entra_auth (bool, Optional): **Deprecated.** Will be removed in 0.15.0.
70+
Authentication is now selected automatically based on what you pass to
71+
``azure_speech_key`` (and ``AZURE_SPEECH_KEY`` env var):
72+
73+
- Pass a **string** API key (or set ``AZURE_SPEECH_KEY``) to use API-key auth.
74+
- Pass a **callable token provider** (sync or async returning a token string)
75+
to use Entra ID with a custom token; ``azure_speech_resource_id`` must also
76+
be set.
77+
- Omit ``azure_speech_key`` entirely to use Entra ID via
78+
``DefaultAzureCredential``; ``azure_speech_resource_id`` must be set.
7179
recognition_language (str): Recognition voice language. Defaults to "en-US".
7280
For more on supported languages, see the following link:
7381
https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support
@@ -76,12 +84,13 @@ def __init__(
7684
ValueError: If the required environment variables or parameters are not set.
7785
"""
7886
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,
87+
print_deprecation_message(
88+
old_item="AzureSpeechAudioToTextConverter(use_entra_auth=...)",
89+
new_item=(
90+
"AzureSpeechAudioToTextConverter("
91+
"azure_speech_key=<api-key-string-or-callable-token-provider-or-omit>)"
92+
),
93+
removed_in="0.15.0",
8594
)
8695

8796
self._azure_speech_region: str = default_values.get_required_value(
@@ -189,11 +198,10 @@ def recognize_audio(self, audio_bytes: bytes) -> str:
189198
ModuleNotFoundError: If the azure.cognitiveservices.speech module is not installed.
190199
"""
191200
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,
201+
print_deprecation_message(
202+
old_item="AzureSpeechAudioToTextConverter.recognize_audio",
203+
new_item="AzureSpeechAudioToTextConverter.convert_async",
204+
removed_in="0.15.0",
197205
)
198206
speech_config = get_speech_config(
199207
resource_id=self._azure_speech_resource_id,

pyrit/prompt_converter/azure_speech_text_to_audio_converter.py

Lines changed: 18 additions & 9 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
@@ -70,8 +70,16 @@ def __init__(
7070
If omitted, Entra ID auth via ``DefaultAzureCredential`` is used automatically.
7171
azure_speech_resource_id (str, Optional): The resource ID for accessing the service when using
7272
Entra ID auth. Required when using a callable token provider or when no API key is available.
73-
use_entra_auth (bool, Optional): **Deprecated.** Will be removed in v0.15.0.
74-
Authentication is now auto-detected from the provided credentials.
73+
use_entra_auth (bool, Optional): **Deprecated.** Will be removed in 0.15.0.
74+
Authentication is now selected automatically based on what you pass to
75+
``azure_speech_key`` (and ``AZURE_SPEECH_KEY`` env var):
76+
77+
- Pass a **string** API key (or set ``AZURE_SPEECH_KEY``) to use API-key auth.
78+
- Pass a **callable token provider** (sync or async returning a token string)
79+
to use Entra ID with a custom token; ``azure_speech_resource_id`` must also
80+
be set.
81+
- Omit ``azure_speech_key`` entirely to use Entra ID via
82+
``DefaultAzureCredential``; ``azure_speech_resource_id`` must be set.
7583
synthesis_language (str): Synthesis voice language.
7684
synthesis_voice_name (str): Synthesis voice name.
7785
For more details see the following link for synthesis language and synthesis voice:
@@ -82,12 +90,13 @@ def __init__(
8290
ValueError: If the required environment variables or parameters are not set.
8391
"""
8492
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,
93+
print_deprecation_message(
94+
old_item="AzureSpeechTextToAudioConverter(use_entra_auth=...)",
95+
new_item=(
96+
"AzureSpeechTextToAudioConverter("
97+
"azure_speech_key=<api-key-string-or-callable-token-provider-or-omit>)"
98+
),
99+
removed_in="0.15.0",
91100
)
92101

93102
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)