Skip to content

MAINT: fix remaining pre-commit failures on main (ty + reST roles)#1938

Merged
romanlutz merged 3 commits into
microsoft:mainfrom
romanlutz:romanlutz/fix-main-ci-pre-commit
Jun 4, 2026
Merged

MAINT: fix remaining pre-commit failures on main (ty + reST roles)#1938
romanlutz merged 3 commits into
microsoft:mainfrom
romanlutz:romanlutz/fix-main-ci-pre-commit

Conversation

@romanlutz
Copy link
Copy Markdown
Contributor

Description

Unblocks main CI (currently RED on commit 309b7a54) and downstream PRs that depend on it (notably #1884, the typing modernization sweep). Companion to #1935, which cleared the dominant missing-override-decorator bucket.

Two pre-commit hooks fail on main today; this PR clears both.

ty (type check) -- 5 errors -> 0

  • pyrit/auth/copilot_authenticator.py: pre-initialize page = None alongside the existing browser / context pre-init. The finally block already references all three, but page was only assigned inside the try -- so an exception from chromium.launch or new_context (before line 391) would dereference an unbound local. Real latent bug, not just a type lint.
  • pyrit/output/score/pretty.py: guard score.scorer_class_identifier for None and fall back to "Unknown", mirroring the existing convention in pyrit/models/score.py.
  • pyrit/scenario/scenarios/adaptive/text_adaptive.py: annotate VERSION as ClassVar[int] = 1 so it matches the parent AdaptiveScenario.VERSION: ClassVar[int] and satisfies LSP. ClassVar was already imported.
  • pyrit/cli/pyrit_shell.py: suppress the os.system soft-deprecation with # type: ignore[ty:deprecated] (PyRIT's mypy-style convention; a subprocess.run rewrite would need shell=True for the Windows cls builtin, which is strictly worse).

Reject Sphinx reST cross-reference roles -- 12 hits -> 0

Replace :class:, :meth:, and :attr: Sphinx roles with double-backtick code spans per PyRIT's MyST docstring convention:

  • pyrit/auxiliary_attacks/gcg/data.py (2)
  • pyrit/auxiliary_attacks/gcg/experiments/run.py (4)
  • pyrit/setup/initializers/components/scenario_techniques.py (6)

Deferred (out of scope)

The same ty run surfaces 9 unused-type-ignore-comment warnings across pyrit/datasets/seed_datasets/remote/{jbb_behaviors,sorry_bench,red_team_social_bias}_dataset.py, pyrit/prompt_target/openai/_openai_realtime_streaming_session.py, and pyrit/scenario/scenarios/foundry/red_team_agent.py. These are warnings (not errors) and do not fail the hook -- left for a follow-up sweep to keep this PR surgical.

Tests and Documentation

No new tests; this is a CI / static-analysis fix. The copilot_authenticator.py change is a defensive pre-init for the exception path -- behavior on the happy path is unchanged.

Verified locally:

  • uv run --link-mode=copy pre-commit run ty-check --all-files -- clean
  • uv run --link-mode=copy pre-commit run check-no-rest-roles --all-files -- clean
  • uv run --link-mode=copy ruff check pyrit/ tests/ doc/ -- clean
  • uv run --link-mode=copy pytest tests/unit -n 8 -q -- 9364 passed, 124 skipped

Clears the ty (type check) hook (5 errors -> 0) and the
Reject Sphinx reST cross-reference roles hook (12 hits -> 0)
so main CI goes green and unblocks downstream PRs.

ty errors:
- pyrit/auth/copilot_authenticator.py: pre-initialize `page = None`
  alongside `browser`/`context` so the `finally` block does not
  dereference an unbound local when `chromium.launch` or
  `new_context` raises before line 391.
- pyrit/output/score/pretty.py: guard `scorer_class_identifier` for
  `None` and fall back to `"Unknown"`, mirroring the existing
  convention in `pyrit/models/score.py`.
- pyrit/scenario/scenarios/adaptive/text_adaptive.py: annotate
  `VERSION` as `ClassVar[int]` to match
  `AdaptiveScenario.VERSION: ClassVar[int]` and satisfy LSP.
- pyrit/cli/pyrit_shell.py: suppress the soft-deprecation warning on
  `os.system` with `# type: ignore[ty:deprecated]` (PyRIT
  mypy-style convention; a `subprocess.run` rewrite would need
  `shell=True` for the Windows `cls` builtin and is strictly
  worse).

reST role replacements (12 occurrences across 3 files): replace
`:class:`, `:meth:`, and `:attr:` Sphinx roles with
double-backtick code spans per PyRIT's MyST convention in:
- pyrit/auxiliary_attacks/gcg/data.py
- pyrit/auxiliary_attacks/gcg/experiments/run.py
- pyrit/setup/initializers/components/scenario_techniques.py

Verified locally:
- pre-commit run ty-check --all-files (clean)
- pre-commit run check-no-rest-roles --all-files (clean)
- ruff check pyrit/ tests/ doc/ (clean)
- pytest tests/unit -n 8 -q (9364 passed, 124 skipped)

The 9 `unused-type-ignore-comment` warnings from the same ty run
are intentionally deferred -- they are warnings, not errors, and do
not fail the hook.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI added 2 commits June 4, 2026 11:29
The ternary fits on one line at the project's 120-char limit; ruff
format requires the single-line form.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz enabled auto-merge June 4, 2026 18:33
@jsong468 jsong468 self-assigned this Jun 4, 2026
@romanlutz romanlutz added this pull request to the merge queue Jun 4, 2026
Merged via the queue into microsoft:main with commit c618c2a Jun 4, 2026
51 of 52 checks passed
@romanlutz romanlutz deleted the romanlutz/fix-main-ci-pre-commit branch June 4, 2026 19:05
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.

5 participants