Skip to content

REFACTOR: Promote scorer-initializer module constants to ClassVar (21 items) - #1974

Merged
romanlutz merged 1 commit into
microsoft:mainfrom
romanlutz:romanlutz/constants-scorers-initializer
Jun 10, 2026
Merged

REFACTOR: Promote scorer-initializer module constants to ClassVar (21 items)#1974
romanlutz merged 1 commit into
microsoft:mainfrom
romanlutz:romanlutz/constants-scorers-initializer

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

Promote 21 module-level UPPER_CASE string constants in
pyrit/setup/initializers/components/scorers.py onto the
ScorerInitializer class as ClassVar[str] (and _PREFERRED_BEST as
ClassVar[dict[str, tuple[str, str]]]). Each constant is used only by
ScorerInitializer, so colocating it with the class better matches the
PyRIT style guide.

This is the largest single-file diff in the constants-audit cleanup
plan and follows the same pattern as #1964 (backend / registry / setup)
and #1965 (prompt_converter).

Constants promoted (21)

  • MAIN_SCORER_TARGET, FALLBACK_SCORER_TARGET
  • MAIN, FALLBACK
  • REFUSAL_GPT4O_OBJECTIVE_STRICT, REFUSAL_GPT4O_OBJECTIVE_LENIENT,
    REFUSAL_GPT4O_NO_OBJECTIVE_STRICT,
    REFUSAL_GPT4O_NO_OBJECTIVE_LENIENT, REFUSAL_GPT5_1,
    REFUSAL_GPT4O_UNSAFE
  • INVERTED_REFUSAL
  • ACS_THRESHOLD_01, ACS_THRESHOLD_07, ACS_WITH_REFUSAL
  • SCALE_AND_REFUSAL
  • ACS_HATE, ACS_SELF_HARM, ACS_SEXUAL, ACS_VIOLENCE
  • TASK_ACHIEVED_GPT4O_TEMP9
  • _PREFERRED_BEST

Constants kept at module level

  • GPT4O_TARGET, GPT4O_TEMP0_TARGET, GPT4O_TEMP9_TARGET,
    GPT4O_UNSAFE_TARGET, GPT4O_UNSAFE_TEMP0_TARGET,
    GPT4O_UNSAFE_TEMP9_TARGET, GPT5_4_TARGET, GPT5_1_TARGET
    imported by name from
    tests/unit/setup/test_scorer_initializer.py, so promoting them
    would be a breaking change.
  • REFUSAL_GPT5_4, ACS_THRESHOLD_05,
    SCALE_GPT4O_TEMP9_THRESHOLD_09,
    TASK_ACHIEVED_REFINED_GPT4O_TEMP9 — referenced by
    ScorerInitializer._PREFERRED_BEST and out of scope for this PR.

No back-compat re-exports needed

None of the 21 promoted constants are imported by name from any other
module under pyrit/, tests/, or doc/ (verified with grep). All
test references use string literals, not symbol imports.

No value changes. No behaviour changes.

Verified

  • uv run --link-mode=copy ruff check pyrit/setup/initializers/components/scorers.py
  • uv run --link-mode=copy ty check pyrit/setup/initializers/components/scorers.py
  • uv run --link-mode=copy pytest tests/unit/setup/ -x --no-header -q
    → 274 passed

Move 21 module-level UPPER_CASE string constants from pyrit/setup/initializers/components/scorers.py onto ScorerInitializer as ClassVar, matching the pattern from microsoft#1964 and microsoft#1965 and the PyRIT style guide rule that class-only constants live on their class.

No value changes. No behaviour changes.

Verified: ruff / ty / pytest tests/unit/setup/.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants