Repository navigation
Description
Broken out from the Python 3.11 adoption tracker #3166 (item P311-01). Seventeen focused Self PRs are already merged (history in #3166); a maintainer-side AST sweep of current main found the remainder below. Claim one PR-sized group at a time by comment; the first commenter on a group may open its PR.
Remaining candidates (verified: each constructs via cls(...)/cls.model_validate(...) or returns self/a copy of self)
Group 1 — pyrit/score (~21 cases, highest value, claim as one PR). Factories: ScorerRequirements.combine, CompatibleScorers.from_scorer (scorer_selection.py:104, :366), InsecureCodeScorer.from_harm_categories (:137), LikertScale.from_yaml (:81), NumericRubric.from_yaml (:69), SelfAskLikertScorer.from_likert_scale (:343), SelfAskScaleScorer.from_scale (:139), HumanLabeledDataset.from_csv (:227), LlamaGuardPolicy.from_yaml (:75), ContentClassifier.from_yaml (:85), SelfAskCategoryScorer.from_content_classifier (:285), TrueFalseQuestion.from_yaml (:82), SelfAskTrueFalseScorer.from_question (:235), ShieldGemmaPolicy.from_yaml/.default (:116, :136). Fluent: the six with_scorer_block_policy overrides (scorer.py:517, message_scorer.py:383, float_scale_threshold_scorer.py:113, true_false_composite_scorer.py:111, true_false_inverter_scorer.py:66, true_false_score_selector.py:44) — converting these also lets the cast("TrueFalseScorer"/...) wrappers at assert_judge_scorer.py:152, float_scale_threshold_scorer.py:125, true_false_composite_scorer.py:123, true_false_inverter_scorer.py:78, true_false_score_selector.py:53 be deleted. ~300–400 lines.
Group 2 — scenario/executor/models/prompt layers (~26 cases, one PR). AttackTechniqueFactory.with_simulated_conversation/.with_attack_kwargs/.with_settings/.with_extra_turns/.with_prepended_history_converters/.with_adversarial_system_prompt_prefix (attack_technique_factory.py:281, :717, :851, :979, :1008, :1043); the two bound-TypeVar signatures AttackParameters.from_seed_group_async (attack_parameters.py:94) and its MultiPromptSendingAttackParameters override (multi_prompt_sending.py:56) — these must change together, and the AttackParamsT TypeVar itself stays (it parameterizes AttackContext); SeedPrompt.with_value (:189), SeedSimulatedConversation.with_settings (:426), Parameter.for_external_catalog (:367), RequestGenerationConfig.from_metadata/.from_message, RequestGenerationInfo.from_metadata/._from_record (request_generation_config.py:49, :64, :128, :148), AssertJudgePreset.from_yaml_file (:204), ScoringExpectation.model_validate_persisted (:110), MCPToolProvider.from_config_file/.from_config (:138, :168), HTTPTarget.with_client (:261), ConversationNormalizationPipeline.from_capabilities (:79), ConverterConfiguration.from_converters (:25, → list[Self]), TokenizerTemplateNormalizer.from_model (:134), CompoundDatasetAttackConfiguration.per_dataset (:1268), SelectorScope.all_runs/.current_run (:46, :56). ~350–450 lines.
Group 3 — infrastructure/backend (~16 cases, one PR). backend: ScoreView.from_domain, MessagePieceView.from_domain (attacks.py:93, :155), DatasetUploadLimits.from_environment (:71), LiveAttack.from_execution (:28, → Self | None); cli: BackendAuthConfig.from_payload (_auth.py:45), PyRITApiClient.__aenter__ (api_client.py:98); memory: ScenarioHistoryAggregate.empty, AttackConversationPage.from_references (memory_interface.py:439, :542); analytics: ScenarioPlanLookup.from_plan (scenario_statistics.py:96); auth: AsyncTokenProviderCredential.__aenter__ (azure_auth.py:160); exceptions: ExecutionContextManager.__enter__ (:205); gcg: RngBundle.from_seed (:103), ModelWorker.start/.stop/.__call__ (attack_manager.py:2342, :2354, :2367); AttackPreparationFailure.from_result (:114, → Self | None); _ObjectiveTargetConversationLifecycle.__aenter__ (attack_strategy.py:150). The __enter__/__aenter__ cases need only an assert_type check. Optional borderline add-ons: ConfigurationLoader.from_dict/.load_with_overrides (needs a generic _ConfigurationLayer or a cast) and the AttackResultKeysetCursor NamedTuple. ~200–300 lines.
Group 4 — optional, mechanical (no tests). 59 pydantic @model_validator(mode="after") methods still annotate the class name where 35 others already use Self (backend/models ×12, models/score ×30, models/seeds ×4, other models ×8, score ×5). Annotation-only, ~100 lines; may ride along per-package in Groups 1–3 instead.
Cautions
SelfAskTrueFalseScorer.from_questionandHTTPTarget.with_clienthave real subclasses (SelfAskQuestionAnswerScorer,HTTPXAPITarget) that may not accept the same__init__kwargs — check subclass constructors before writing the subclass test.- Excluded by design (do not convert): enum classmethods (members block subclassing), factories delegating to module functions that hard-code the class (
SeedDataset.from_yaml_file,SeedPrompt.from_yaml_with_required_parameters), hard-coded constructions whereSelfwould change behavior (Message.duplicate,RandomContext.child,TechniqueBundle.bind_async, etc.),ScorerEvaluator.from_scorer(picks a concrete subclass),AttackParameters.excluding(make_dataclass), and the standing Python 3.11 adoption opportunities: claim one improvement at a time #3166 exclusions (TagQuery.__and__/__or__,ComponentIdentifier.with_eval_hash,SeedPrompt.from_value_with_required_parameters).
House pattern per case: Self annotation + subclass runtime/assert_type coverage (group into parametrized tests per file to keep the diff sane). Groups 1 and 2 are independent and can be claimed by different contributors.
Activity
SpinachDigital commentedon Nov 21, 2026
I'll take Group 1 (pyrit/score) — converting the ~21 typing.Self cases as one PR.
uday-kasturi commentedon Nov 22, 2026
I'd like to take Group 3 (infrastructure and backend), all 17 cases, with subclass and assert_type tests.
victorpreston commentedon Nov 22, 2026
I'd like to take Group 2 (scenario / executor / models / prompt layers), all 26 cases as one PR, with subclass and assert_type tests.
MAINT: adopt typing.Self in pyrit/score/float_scale (Group 1 of micro…
MAINT: adopt typing.Self in pyrit/score (Group 1 of microsoft#4504)
MAINT: adopt typing.Self in pyrit/score/scorer_evaluation (Group 1 of m…
MAINT: adopt typing.Self in pyrit/score/true_false (Group 1 of micros…
MAINT: adopt typing.Self tests in tests/unit/score (Group 1 of micros…
MAINT: adopt typing.Self in pyrit/score (Group 1 of microsoft#4504) —…
MAINT: adopt typing.Self in pyrit/score (Group 1 of microsoft#4504) —…
MAINT: adopt typing.Self in pyrit/score (Group 1 of microsoft#4504) —…
MAINT: carry upstream ty rename in composite scorer (Group 1 of micro…
MAINT: carry upstream ty rename in inverter scorer (Group 1 of micros…
MAINT: resolve scorer.py import conflict with upstream main (Group 1 of
MAINT: adopt typing.Self in pyrit/score (Group 1 of microsoft#4504) —…
MAINT: adopt typing.Self in pyrit/score (Group 1 of microsoft#4504) —…
MAINT: adopt typing.Self in pyrit/score (Group 1 of microsoft#4504) —…
MAINT: adopt typing.Self in pyrit/score (Group 1 of microsoft#4504) —…
MAINT: adopt typing.Self in pyrit/score (Group 1 of microsoft#4504) —…
Remove now-redundant cast in scenario.py (Self return makes it redund…