Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ dependencies = [
"reportlab>=4.4.4",
# 2026.11.x breaks \X on Indic conjuncts (GB9c never applies, mrab-regex#636), which graphemes() relies on.
# Remove the upper bound once that is fixed upstream (#4308).
"regex>=2024.11.6,<2026.11",
"regex>=2024.11.6,<2026.12",
"segno>=1.6.6",
"scipy>=1.15.3",
"SQLAlchemy[asyncio]>=2.0.41",
Expand Down Expand Up @@ -280,7 +280,7 @@ redundant-condition-strict = "ignore"
[[tool.ty.overrides]]
include = ["tests/unit/**"]
[tool.ty.overrides.rules]
call-non-callable = "ignore"
not-callable = "ignore"
invalid-assignment = "ignore"
invalid-await = "ignore"
invalid-parameter-default = "ignore"
Expand All @@ -294,9 +294,9 @@ unsupported-operator = "ignore"
# relaxed here: tests read private/mock attributes and subclass library types
# with loosened signatures / runtime-validation-failure arguments.
invalid-argument-type = "ignore"
invalid-method-override = "ignore"
incompatible-method-override = "ignore"
no-matching-overload = "ignore"
unresolved-attribute = "ignore"
missing-attribute = "ignore"
# Enabled for pyrit/ (clean) but still relaxed here: tests/unit has 318 bare
# generics (mostly `dict` and the attack context/strategy classes) across ~70 files.
missing-type-argument = "ignore"
Expand Down
2 changes: 1 addition & 1 deletion pyrit/backend/models/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class FindingListItem(Finding):
evidence_count: int = Field(ge=0)
child_count: int = Field(ge=0, description="The number of direct sub-findings")
# A response narrows each path to include its derived completeness; list items are never reassigned.
paths: tuple[FindingPathItem, ...] = () # type: ignore[ty:invalid-mutable-override]
paths: tuple[FindingPathItem, ...] = () # type: ignore[ty:incompatible-mutable-override]


class AttackFindingItem(Finding):
Expand Down
4 changes: 2 additions & 2 deletions pyrit/backend/pyrit_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def main(*, args: list[str] | None = None) -> int:
Returns:
int: Exit code (0 for success, 1 for error).
"""
sys.stdout.reconfigure(errors="replace") # type: ignore[ty:unresolved-attribute]
sys.stderr.reconfigure(errors="replace") # type: ignore[ty:unresolved-attribute]
sys.stdout.reconfigure(errors="replace") # type: ignore[ty:missing-union-attribute]
sys.stderr.reconfigure(errors="replace") # type: ignore[ty:missing-union-attribute]

try:
parsed_args = parse_args(args=args)
Expand Down
2 changes: 1 addition & 1 deletion pyrit/cli/_cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _argparse_validator(validator_func: Callable[..., Any]) -> Callable[[Any], A
sig = inspect.signature(validator_func)
params = list(sig.parameters.keys())
if not params:
raise ValueError(f"Validator function {validator_func.__name__} must have at least one parameter") # type: ignore[ty:unresolved-attribute]
raise ValueError(f"Validator function {validator_func.__name__} must have at least one parameter") # type: ignore[ty:missing-attribute]
first_param = params[0]

def wrapper(value: Any) -> Any:
Expand Down
4 changes: 2 additions & 2 deletions pyrit/common/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def print_deprecation_message(
"""
# Get the qualified name for old item
if callable(old_item) or isinstance(old_item, type):
old_name = f"{old_item.__module__}.{old_item.__qualname__}" # type: ignore[ty:unresolved-attribute]
old_name = f"{old_item.__module__}.{old_item.__qualname__}" # type: ignore[ty:missing-attribute]
else:
old_name = old_item

# Get the qualified name for new item
if callable(new_item) or isinstance(new_item, type):
new_name = f"{new_item.__module__}.{new_item.__qualname__}" # type: ignore[ty:unresolved-attribute]
new_name = f"{new_item.__module__}.{new_item.__qualname__}" # type: ignore[ty:missing-attribute]
else:
new_name = new_item

Expand Down
2 changes: 1 addition & 1 deletion pyrit/common/yaml_loadable.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def from_yaml_file(cls, file: Path | str) -> Self:
# If this class provides a from_dict factory, use it;
# otherwise, just instantiate directly with **yaml_data
if hasattr(cls, "from_dict") and callable(getattr(cls, "from_dict")): # noqa: B009
result: Self = cls.from_dict(yaml_data) # type: ignore[ty:call-non-callable]
result: Self = cls.from_dict(yaml_data) # type: ignore[ty:not-callable]
return result
return cls(**yaml_data)
2 changes: 1 addition & 1 deletion pyrit/converter/selective_text_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ async def _convert_word_level_async(self, *, prompt: str) -> ConverterResult:
words = prompt.split(self._word_separator)

# Get selected word indices
selected_indices = self._selection_strategy.select_words(words=words) # type: ignore[ty:unresolved-attribute]
selected_indices = self._selection_strategy.select_words(words=words) # type: ignore[ty:missing-attribute]

# If no words selected, return original prompt
if not selected_indices:
Expand Down
4 changes: 2 additions & 2 deletions pyrit/executor/attack/core/attack_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,6 @@ async def from_seed_group_wrapper_async(
c, seed_group=seed_group, adversarial_chat=adversarial_chat, objective_scorer=objective_scorer, **ov
)

new_cls.from_seed_group_async = classmethod(from_seed_group_wrapper_async) # type: ignore[ty:unresolved-attribute]
new_cls.from_seed_group_async = classmethod(from_seed_group_wrapper_async) # type: ignore[ty:missing-attribute]

return new_cls # type: ignore[ty:invalid-return-type]
return new_cls # type: ignore[ty:invalid-explicit-return]
2 changes: 1 addition & 1 deletion pyrit/executor/promptgen/anecdoctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ async def _extract_knowledge_graph_async(self, *, context: AnecdoctorContext) ->

# Format the cached KG extraction prompt. _kg_prompt_template is set in __init__
# whenever _processing_model is set, so the guard above already implies it is non-None here.
kg_system_prompt = self._kg_prompt_template.format(language=context.language) # type: ignore[ty:unresolved-attribute]
kg_system_prompt = self._kg_prompt_template.format(language=context.language) # type: ignore[ty:missing-union-attribute]

# Create a separate conversation ID for KG extraction
kg_conversation_id = str(uuid.uuid4())
Expand Down
4 changes: 2 additions & 2 deletions pyrit/memory/memory_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,7 @@ def _query_entries(
query = query.limit(limit)
return query.all()
except SQLAlchemyError as e:
logger.exception(f"Error fetching data from table {model_class.__tablename__}: {e}") # type: ignore[ty:unresolved-attribute]
logger.exception(f"Error fetching data from table {model_class.__tablename__}: {e}") # type: ignore[ty:missing-attribute]
raise

def _execute_batched_query(
Expand Down Expand Up @@ -3250,7 +3250,7 @@ def _update_entries(self, *, entries: MutableSequence[Base], update_fields: dict
):
raise ValueError("Prompt entries used by scorer observations are immutable.")
for entry in entries:
entry_in_session = session.get(type(entry), entry.id) # type: ignore[ty:unresolved-attribute]
entry_in_session = session.get(type(entry), entry.id) # type: ignore[ty:missing-attribute]
if isinstance(entry, (AttackResultEntry, ScenarioResultEntry)):
assert entry_in_session is None or isinstance(
entry_in_session, (AttackResultEntry, ScenarioResultEntry)
Expand Down
2 changes: 1 addition & 1 deletion pyrit/memory/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ async def is_file_async(self, path: Path | str) -> bool:
finally:
await self._close_client_async()

async def create_directory_if_not_exists_async(self, directory_path: Path | str) -> None: # type: ignore[ty:invalid-method-override]
async def create_directory_if_not_exists_async(self, directory_path: Path | str) -> None: # type: ignore[ty:lost-keyword-for-regular-parameter]
"""
Log a no-op directory creation for Azure Blob Storage.

Expand Down
2 changes: 1 addition & 1 deletion pyrit/models/messages/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _validate_invariants(self) -> None:
if message_piece.role != role:
raise ValueError("Inconsistent roles within the same message entry.")

def validate(self) -> None: # type: ignore[ty:invalid-method-override]
def validate(self) -> None: # type: ignore[ty:incompatible-method-override]
"""
Validate that all message pieces are internally consistent.

Expand Down
2 changes: 1 addition & 1 deletion pyrit/models/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def validate_value(self, value: Any) -> None:
except ValidationError as exc:
raise ValueError(f"Parameter '{self.name}' expects {self.type_name}: {exc}") from exc

def validate(self) -> None: # type: ignore[ty:invalid-method-override]
def validate(self) -> None: # type: ignore[ty:incompatible-method-override]
"""
Reject a declaration with an unsupported ``param_type``.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ async def _send_prompt_to_target_async(self, *, normalized_conversation: list[Me

assistant_response = cast(
"str",
self.tokenizer.decode(generated_tokens, skip_special_tokens=self.skip_special_tokens), # type: ignore[ty:unresolved-attribute]
self.tokenizer.decode(generated_tokens, skip_special_tokens=self.skip_special_tokens), # type: ignore[ty:missing-union-attribute]
).strip()

truncated = self._is_truncated(generated_tokens=generated_tokens)
Expand Down
2 changes: 1 addition & 1 deletion pyrit/prompt_target/prompt_shield_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _add_auth_param_to_headers(self, headers: dict[str, str]) -> None:
if self._api_key:
# If callable, call it to get the token
if callable(self._api_key):
token = self._api_key() # type: ignore[ty:call-top-callable]
token = self._api_key() # type: ignore[ty:call-to-function-with-unknown-signature]
headers["Authorization"] = f"Bearer {token}"
else:
# String API key
Expand Down
2 changes: 1 addition & 1 deletion pyrit/registry/components/attack_technique_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def _get_aggregate_tags(cls: type) -> set[str]:
# When it wasn't, the attribute is left unset and ScenarioTechnique.default() owns
# the single ALL fallback — so the "no default -> ALL" rule lives in one place.
if default_member_names:
technique_cls._default_technique_value = "default" # type: ignore[ty:unresolved-attribute]
technique_cls._default_technique_value = "default" # type: ignore[ty:missing-attribute]

return technique_cls

Expand Down
6 changes: 3 additions & 3 deletions pyrit/registry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,18 @@ def get_registry_singleton(cls) -> Self:
with cls._singletons_lock:
instance = cls._singletons.get(cls)
if instance is not None:
return instance # type: ignore[ty:invalid-return-type]
return instance # type: ignore[ty:invalid-explicit-return]
construction_lock = cls._singleton_construction_locks.setdefault(cls, threading.Lock())

with construction_lock:
with cls._singletons_lock:
instance = cls._singletons.get(cls)
if instance is not None:
return instance # type: ignore[ty:invalid-return-type]
return instance # type: ignore[ty:invalid-explicit-return]
instance = cls()
with cls._singletons_lock:
cls._singletons[cls] = instance
return instance # type: ignore[ty:invalid-return-type]
return instance # type: ignore[ty:invalid-explicit-return]

@classmethod
def reset_registry_singleton(cls) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _build_image_technique_adaptive_technique() -> type[ScenarioTechnique]:
Returns:
type[ScenarioTechnique]: The dynamically-built technique enum class.
"""
return AttackTechniqueRegistry.build_technique_class_from_factories( # type: ignore[return-value, ty:invalid-return-type]
return AttackTechniqueRegistry.build_technique_class_from_factories( # type: ignore[return-value, ty:invalid-explicit-return]
class_name="ImageTechniqueAdaptiveTechnique",
factories=_image_technique_factories(),
default_names={"blank_canvas", "grid_composite", "comic_panel"},
Expand Down
2 changes: 1 addition & 1 deletion pyrit/scenario/scenarios/adaptive/text_adaptive.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _build_text_adaptive_technique() -> type[ScenarioTechnique]:

factories = [factory for factory in all_factories if factory.name not in _EXCLUDED_TECHNIQUES]

return AttackTechniqueRegistry.build_technique_class_from_factories( # type: ignore[return-value, ty:invalid-return-type]
return AttackTechniqueRegistry.build_technique_class_from_factories( # type: ignore[return-value, ty:invalid-explicit-return]
class_name="TextAdaptiveTechnique",
factories=factories,
default_names={"role_play_movie_script", "many_shot"},
Expand Down
2 changes: 1 addition & 1 deletion pyrit/scenario/scenarios/airt/jailbreak.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _build_jailbreak_technique() -> type[ScenarioTechnique]:
Returns:
type[ScenarioTechnique]: The dynamically generated technique enum class.
"""
return AttackTechniqueRegistry.build_technique_class_from_factories( # type: ignore[return-value, ty:invalid-return-type]
return AttackTechniqueRegistry.build_technique_class_from_factories( # type: ignore[return-value, ty:invalid-explicit-return]
class_name="JailbreakTechnique",
factories=list(_extra_default_factories().values()),
default_names=set(_DEFAULT_TECHNIQUES),
Expand Down
2 changes: 1 addition & 1 deletion pyrit/scenario/scenarios/garak/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _build_doctor_technique() -> type[ScenarioTechnique]:
Returns:
type[ScenarioTechnique]: The dynamically generated technique enum class.
"""
return AttackTechniqueRegistry.build_technique_class_from_factories( # type: ignore[return-value, ty:invalid-return-type]
return AttackTechniqueRegistry.build_technique_class_from_factories( # type: ignore[return-value, ty:invalid-explicit-return]
class_name="DoctorTechnique",
factories=DOCTOR_FACTORIES,
default_names={"policy_puppetry", "policy_puppetry_leet"},
Expand Down
2 changes: 1 addition & 1 deletion pyrit/score/float_scale/video_float_scale_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _build_identifier(self) -> ComponentIdentifier:
"image_objective_template": self._video_helper.image_objective_template,
"audio_objective_template": self._video_helper.audio_objective_template,
},
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:unresolved-attribute]
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:missing-attribute]
sub_scorers=sub_scorer_ids,
)

Expand Down
14 changes: 7 additions & 7 deletions pyrit/score/scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async def _legacy_score_scorable_async(
)
resolver = getattr(self, "_message_resolver", None) or MessageScorableResolver()
message = await resolver.resolve_async(scorable=scorable, memory=self._memory)
legacy_score_async = self._score_async # type: ignore[ty:unresolved-attribute]
legacy_score_async = self._score_async # type: ignore[ty:missing-attribute]
with _scoring_message_context(message):
scores: list[Score] = await legacy_score_async(
message,
Expand Down Expand Up @@ -274,15 +274,15 @@ def defines(name: str) -> bool:
else:
score_async = MessageScorer._score_async

cls._score_async = score_async # type: ignore[ty:invalid-assignment, ty:unresolved-attribute]
cls._score_async = score_async # type: ignore[ty:invalid-assignment, ty:missing-attribute]
if not defines("_score_piece_with_expectation_async"):
cls._score_piece_with_expectation_async = MessageScorer._score_piece_with_expectation_async # type: ignore[ty:invalid-assignment, ty:unresolved-attribute]
cls._score_piece_with_expectation_async = MessageScorer._score_piece_with_expectation_async # type: ignore[ty:invalid-assignment, ty:missing-attribute]
if not defines("_get_supported_pieces"):
cls._get_supported_pieces = MessageScorer._get_supported_pieces # type: ignore[ty:invalid-assignment, ty:unresolved-attribute]
cls._get_supported_pieces = MessageScorer._get_supported_pieces # type: ignore[ty:invalid-assignment, ty:missing-attribute]

if not cls.SUPPORTED_SCORABLE_TYPES: # type: ignore[ty:unresolved-attribute]
cls.SUPPORTED_SCORABLE_TYPES = MessageScorer.SUPPORTED_SCORABLE_TYPES # type: ignore[ty:unresolved-attribute]
cls._score_scorable_async = _legacy_score_scorable_async # type: ignore[ty:invalid-assignment, ty:unresolved-attribute]
if not cls.SUPPORTED_SCORABLE_TYPES: # type: ignore[ty:missing-attribute]
cls.SUPPORTED_SCORABLE_TYPES = MessageScorer.SUPPORTED_SCORABLE_TYPES # type: ignore[ty:missing-attribute]
cls._score_scorable_async = _legacy_score_scorable_async # type: ignore[ty:invalid-assignment, ty:missing-attribute]


class Scorer(Identifiable, abc.ABC):
Expand Down
2 changes: 1 addition & 1 deletion pyrit/score/true_false/decoding_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _build_identifier(self) -> ComponentIdentifier:
"text_matcher": self._text_matcher.__class__.__name__,
"text_matcher_params": get_matcher_params() if callable(get_matcher_params) else None,
},
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:unresolved-attribute]
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:missing-attribute]
)

async def _score_piece_with_expectation_async(
Expand Down
6 changes: 3 additions & 3 deletions pyrit/score/true_false/float_scale_threshold_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def _build_identifier(self) -> ComponentIdentifier:
return self._create_identifier(
params={
"threshold": self._threshold,
"float_scale_aggregator": self._float_scale_aggregator.__name__, # type: ignore[ty:unresolved-attribute]
"float_scale_aggregator": self._float_scale_aggregator.__name__, # type: ignore[ty:missing-attribute]
},
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:unresolved-attribute]
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:missing-attribute]
sub_scorers=[self._scorer.get_identifier()],
)

Expand Down Expand Up @@ -226,7 +226,7 @@ def _apply_threshold(
# threshold can only be applied to a single value. Silently taking the
# first one would decide the verdict from one category and drop the rest.
raise ValueError(
f"{self._float_scale_aggregator.__name__} returned {len(aggregate_results)} results. " # type: ignore[ty:unresolved-attribute]
f"{self._float_scale_aggregator.__name__} returned {len(aggregate_results)} results. " # type: ignore[ty:missing-attribute]
"FloatScaleThresholdScorer requires an aggregator that combines the scores into exactly "
"one result, such as FloatScaleScoreAggregator.MAX; a by-category aggregator such as "
"FloatScaleScorerByCategory.MAX cannot be thresholded."
Expand Down
2 changes: 1 addition & 1 deletion pyrit/score/true_false/llamaguard_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _build_identifier(self) -> ComponentIdentifier:
"policy": self._policy.model_dump(),
"prompt_template": self._prompt_template.value,
},
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:unresolved-attribute]
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:missing-attribute]
prompt_target=self._prompt_target.get_identifier(),
)

Expand Down
2 changes: 1 addition & 1 deletion pyrit/score/true_false/local_refusal_classifier_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def _build_identifier(self) -> ComponentIdentifier:
"recipe": recipe,
"recipe_digest": digest,
},
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:unresolved-attribute]
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:missing-attribute]
)

def _build_fallback_score(self, *, message: Message, objective: str | None) -> list[Score]:
Expand Down
2 changes: 1 addition & 1 deletion pyrit/score/true_false/multi_label_true_false_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _build_identifier(self) -> ComponentIdentifier:
"""
return self._create_identifier(
params={"labels": list(self.labels)},
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:unresolved-attribute]
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:missing-attribute]
)

@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion pyrit/score/true_false/output_matches_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(
def _build_identifier(self) -> ComponentIdentifier:
return self._create_identifier(
params={"matching_version": 1},
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:unresolved-attribute]
score_aggregator=self._score_aggregator.__name__, # type: ignore[ty:missing-attribute]
)

async def _score_piece_with_expectation_async(
Expand Down
Loading
Loading