Repository navigation
Description
Broken out from the Python 3.11 adoption tracker #3166 (item P311-03). Eleven focused assert_never PRs are merged (history in #3166); a maintainer-side sweep of every enum/Literal dispatch on current main found 19 remaining closed-set sites. Claim one batch at a time by comment; the first commenter on a batch may open its PR.
House pattern (established by the merged PRs): a TYPE_CHECKING-only assert_never guard that preserves any existing runtime fallback, plus an enum-extension type-regression test. Some sites first need an implicit else made explicit, or member.value == "x" comparisons changed to member is Enum.X so narrowing works.
Batch A — Literal-based converters and normalizer (5 files)
pyrit/message_normalizer/message_normalizer.py:120-132—SystemMessageBehaviorLiteral, 3/3 handled, runtime raise commented "should never happen". Cleanest case.pyrit/converter/base64_converter.py:75-92—EncodingFuncLiteral, 8/8 then raise; also annotateself._encoding_func(line 42).pyrit/converter/bin_ascii_converter.py:64-69, 98-104— 3-value Literal, two dispatch sites; also annotateself._encoding_func(line 59).pyrit/converter/pinyin_converter.py:167-170—PinyinMode, "full" is an implicit no-op; make it explicit before guarding.pyrit/converter/unicode_confusable_converter.py:101-106— 3-valuesource_packageLiteral; annotateself._source_package(line 66).
Batch B — score (4 files)
pyrit/score/float_scale/plagiarism_scorer.py:253-271—PlagiarismMetric, 3/3 but compared via.value ==(doesn't narrow); switch toiscomparisons.pyrit/score/response_handler.py:124-129—CategoryConflictPolicy, REJECT_CONFLICT implicit; make explicit.pyrit/score/true_false/wildguard_parser.py:49-56—WildGuardLabel.description, implicit final return.pyrit/score/true_false/regex/package_hallucination_scorer.py:489-504—PackageEcosystem(7 members), JAVASCRIPT implicit no-op.
Batch C — executor and prompt_target (4 files, 7 sites)
pyrit/executor/attack/compound/sequential_attack.py:470-478, 480-500—SequenceCompletionPolicy(5 members), two sites with commented fallthroughs; make membership explicit.pyrit/executor/promptgen/assert_generator.py:408-448, 725-738, 1029-1034—AssertGenerationStage×2 (second site must explicitly reject SEED_GROUPS, which is invalid there) andAssertSamplingMethod.pyrit/prompt_target/openai/openai_response_target.py:592-605—WebSearchMode, DISABLED implicit.pyrit/auth/openai_auth.py:47-75—AuthModeLiteral, "api_key" is the long implicit fallthrough; guard withif auth_mode != "api_key": assert_never(auth_mode).
Batch D — memory, cli, scenario, datasets (6 files, 7 sites)
pyrit/memory/attack_analytics_query.py:773-837—AttackAnalyticsDimensionName(9 members), MODEL implicit; noteself._ensure_identifiers()runs between branches, so place the guard just before the MODEL block.pyrit/memory/memory_models.py:1973-2060—SeedEntry.get_seedover DB-backedSeedType; type-only guard, keep the runtime fallthrough.pyrit/memory/dataset_mutation.py:115-140—seed_replacementoverSeedType, objective implicit.pyrit/cli/_target_credentials.py:48-53, 71-76—CredentialSourceKind, two sites with implicit members.pyrit/scenario/core/_attack_constructor_compatibility.py:95-108—ScorerOverridePolicy, SKIP implicit no-op.pyrit/datasets/seed_datasets/remote/medsafetybench_dataset.py:58-80— 4-valuesubset_nameLiteral, 4/4 then raise.
Optional Tier-2 riders (only if a batch PR passes nearby)
FindingExportFormat in pyrit/backend/services/finding_export.py:97 and get_assert_failure_criterion in pyrit/score/true_false/assert_policy_scorer.py:560. The other ~13 binary/ternary sites surveyed are not worth guards.
Out of scope (deliberately open or partial — do not guard)
Partial AttackOutcome dispatches in attacks (deliberate "everything else" buckets), provider protocol event routers (realtime, websocket Copilot, OpenAI response types), OutputFormat functions that support subsets by design, dict-lookup dispatch, parameters typed str or Enum | str (can't narrow), and predicate-style checks. The sweep's full rejection list is recorded in the tracker notes.
Estimated size: ~25-40 lines per site including the extension-regression test; each batch lands at roughly 150-300 lines.
Activity
InesZenkri commentedon Nov 21, 2026
Roman Lutz (@romanlutz) I'd like to take Batch A, adding exhaustive-dispatch guards and regression tests.
DevShoaib78 commentedon Nov 21, 2026
I would like to take Batch B (score):
PlagiarismMetric(switching the.value ==checks tois),CategoryConflictPolicy(explicit REJECT_CONFLICT),WildGuardLabel.descriptionandPackageEcosystem(explicit JAVASCRIPT), with the TYPE_CHECKINGassert_neverguards and the enum-extension regression tests.Sandro850 commentedon Nov 22, 2026
Hi! I'd like to take Batch D (memory, CLI, scenario, and datasets).
I'll follow the existing
TYPE_CHECKING/assert_neverpattern, preserve the current runtime behavior, and add focused type-regression tests for the seven dispatch sites.I'll also run the relevant tests and
make tybefore submitting the PR.Thanks!
mcjim1689 commentedon Nov 23, 2026
Hi, I'd like to take one slice of this (#4506): Batch C - executor and prompt_target (4 files, 7 sites). (AI-assisted; reviewed and tested before submitting.)