Skip to content

Commit f0db060

Browse files
FIX: Move AttackStrategy import to TYPE_CHECKING to break circular import
PR #1881 (Pydantic identifiers refactor) re-merged with this PR's compute_inner_attack_eval_hash addition and hoisted rom pyrit.executor.attack.core.attack_strategy import AttackStrategy to module level. That import triggers a cycle through `pyrit.executor.attack` -> `pyrit.message_normalizer` -> `pyrit.common.data_url_converter` -> `pyrit.models`, which fails because `pyrit.models` is still being initialised at that point (DataTypeSerializer is not yet defined). `from __future__ import annotations` is already enabled, so the type annotation `attack: AttackStrategy` works as a string. Moving the import inside `if TYPE_CHECKING:` restores the original lazy boundary and unblocks CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 115d1f7 commit f0db060

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

pyrit/models/identifiers/evaluation_identifier.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
from __future__ import annotations
2424

2525
from abc import ABC
26-
from typing import Any, ClassVar, Optional
26+
from typing import TYPE_CHECKING, Any, ClassVar, Optional
2727

2828
from pydantic import BaseModel, ConfigDict, Field
2929

30-
from pyrit.executor.attack.core.attack_strategy import AttackStrategy
3130
from pyrit.models.identifiers.component_identifier import ComponentIdentifier, config_hash
3231

32+
if TYPE_CHECKING:
33+
from pyrit.executor.attack.core.attack_strategy import AttackStrategy
34+
3335
# Behavioral params that define model output quality for scoring.
3436
TARGET_EVAL_PARAMS: frozenset[str] = frozenset({"underlying_model_name", "temperature", "top_p"})
3537
TARGET_EVAL_PARAM_FALLBACKS: dict[str, str] = {"underlying_model_name": "model_name"}

0 commit comments

Comments
 (0)