Skip to content

Commit 86172c9

Browse files
rlundeen2Copilot
andcommitted
Fix ruff lint errors: return types, docstrings, noqa
- Added return type annotation (-> type) to all __getattr__ deprecation shims - Added noqa: B027 to display_image_async intentional no-op default - Added Returns/Raises sections to short docstrings (DOC201, DOC501) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f31d0d0 commit 86172c9

11 files changed

Lines changed: 47 additions & 14 deletions

File tree

pyrit/executor/attack/printer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import warnings as _warnings
1212

1313

14-
def __getattr__(name: str): # noqa: N807
14+
def __getattr__(name: str) -> type: # noqa: N807
1515
_deprecated = {
1616
"ConsoleAttackResultPrinter": "pyrit.printer.attack_result.console",
1717
"MarkdownAttackResultPrinter": "pyrit.printer.attack_result.markdown",

pyrit/executor/attack/printer/console_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import warnings as _warnings
1010

1111

12-
def __getattr__(name: str): # noqa: N807
12+
def __getattr__(name: str) -> type: # noqa: N807
1313
if name == "ConsoleAttackResultPrinter":
1414
_warnings.warn(
1515
"Importing ConsoleAttackResultPrinter from pyrit.executor.attack.printer.console_printer is deprecated "

pyrit/executor/attack/printer/markdown_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import warnings as _warnings
1010

1111

12-
def __getattr__(name: str): # noqa: N807
12+
def __getattr__(name: str) -> type: # noqa: N807
1313
if name == "MarkdownAttackResultPrinter":
1414
_warnings.warn(
1515
"Importing MarkdownAttackResultPrinter from pyrit.executor.attack.printer.markdown_printer is deprecated "

pyrit/printer/attack_result/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def get_scores_async(self, *, prompt_ids: list[str]) -> list[Score]:
4141
list[Score]: The scores associated with the given piece IDs.
4242
"""
4343

44-
async def display_image_async(self, piece: object) -> None:
44+
async def display_image_async(self, piece: object) -> None: # noqa: B027
4545
"""
4646
Display an image from a message piece. No-op by default.
4747

pyrit/printer/attack_result/console.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,21 @@ def __init__(self, *, width: int = 100, indent_size: int = 2, enable_colors: boo
507507
self._memory = CentralMemory.get_memory_instance()
508508

509509
async def get_conversation_async(self, conversation_id: str) -> list[Message]:
510-
"""Fetch conversation messages from CentralMemory."""
510+
"""
511+
Fetch conversation messages from CentralMemory.
512+
513+
Returns:
514+
list[Message]: The conversation messages.
515+
"""
511516
return list(self._memory.get_conversation(conversation_id=conversation_id))
512517

513518
async def get_scores_async(self, *, prompt_ids: list[str]) -> list[Score]:
514-
"""Fetch scores from CentralMemory."""
519+
"""
520+
Fetch scores from CentralMemory.
521+
522+
Returns:
523+
list[Score]: The scores.
524+
"""
515525
return list(self._memory.get_prompt_scores(prompt_ids=prompt_ids))
516526

517527
async def display_image_async(self, piece: object) -> None:

pyrit/printer/attack_result/markdown.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,19 @@ def __init__(self, *, display_inline: bool = True) -> None:
574574
self._memory = CentralMemory.get_memory_instance()
575575

576576
async def get_conversation_async(self, conversation_id: str) -> list[Message]:
577-
"""Fetch conversation messages from CentralMemory."""
577+
"""
578+
Fetch conversation messages from CentralMemory.
579+
580+
Returns:
581+
list[Message]: The conversation messages.
582+
"""
578583
return list(self._memory.get_conversation(conversation_id=conversation_id))
579584

580585
async def get_scores_async(self, *, prompt_ids: list[str]) -> list[Score]:
581-
"""Fetch scores from CentralMemory."""
586+
"""
587+
Fetch scores from CentralMemory.
588+
589+
Returns:
590+
list[Score]: The scores.
591+
"""
582592
return list(self._memory.get_prompt_scores(prompt_ids=prompt_ids))

pyrit/printer/scorer/console.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def __init__(self, *, indent_size: int = 2, enable_colors: bool = True) -> None:
2727
Args:
2828
indent_size (int): Number of spaces for indentation. Defaults to 2.
2929
enable_colors (bool): Whether to enable ANSI color output. Defaults to True.
30+
31+
Raises:
32+
ValueError: If indent_size is negative.
3033
"""
3134
if indent_size < 0:
3235
raise ValueError("indent_size must be non-negative")
@@ -220,15 +223,25 @@ class ConsoleScorerMemoryPrinter(ConsoleScorerPrinterBase):
220223
"""
221224

222225
def get_objective_metrics(self, *, eval_hash: str) -> Any:
223-
"""Fetch objective scorer evaluation metrics from the registry."""
226+
"""
227+
Fetch objective scorer evaluation metrics from the registry.
228+
229+
Returns:
230+
ObjectiveScorerMetrics or None: The metrics, or None if not found.
231+
"""
224232
from pyrit.score.scorer_evaluation.scorer_metrics_io import (
225233
find_objective_metrics_by_eval_hash,
226234
)
227235

228236
return find_objective_metrics_by_eval_hash(eval_hash=eval_hash)
229237

230238
def get_harm_metrics(self, *, eval_hash: str, harm_category: str) -> Any:
231-
"""Fetch harm scorer evaluation metrics from the registry."""
239+
"""
240+
Fetch harm scorer evaluation metrics from the registry.
241+
242+
Returns:
243+
HarmScorerMetrics or None: The metrics, or None if not found.
244+
"""
232245
from pyrit.score.scorer_evaluation.scorer_metrics_io import (
233246
find_harm_metrics_by_eval_hash,
234247
)

pyrit/scenario/printer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import warnings as _warnings
1212

1313

14-
def __getattr__(name: str): # noqa: N807
14+
def __getattr__(name: str) -> type: # noqa: N807
1515
_deprecated = {
1616
"ConsoleScenarioResultPrinter": "pyrit.printer.scenario_result.console",
1717
"ScenarioResultPrinter": "pyrit.printer.scenario_result.base",

pyrit/scenario/printer/console_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import warnings as _warnings
1010

1111

12-
def __getattr__(name: str): # noqa: N807
12+
def __getattr__(name: str) -> type: # noqa: N807
1313
if name == "ConsoleScenarioResultPrinter":
1414
_warnings.warn(
1515
"Importing ConsoleScenarioResultPrinter from pyrit.scenario.printer.console_printer is deprecated "

pyrit/score/printer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import warnings as _warnings
1212

1313

14-
def __getattr__(name: str): # noqa: N807
14+
def __getattr__(name: str) -> type: # noqa: N807
1515
_deprecated = {
1616
"ConsoleScorerPrinter": "pyrit.printer.scorer.console",
1717
"ScorerPrinter": "pyrit.printer.scorer.base",

0 commit comments

Comments
 (0)