Skip to content

REFACTOR: Promote printer dimension defaults (width / blur_radius / font_size) to ClassVar on printer base - #1969

Closed
Roman Lutz (romanlutz) wants to merge 1 commit into
microsoft:mainfrom
romanlutz:romanlutz/refactor-printer-dimension-defaults
Closed

REFACTOR: Promote printer dimension defaults (width / blur_radius / font_size) to ClassVar on printer base#1969
Roman Lutz (romanlutz) wants to merge 1 commit into
microsoft:mainfrom
romanlutz:romanlutz/refactor-printer-dimension-defaults

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Summary

Promotes printer dimension defaults (width = 100, blur_radius = 20) from per-constructor hard-coded literals to ClassVar[int] attributes on PrinterBase in pyrit/output/base.py:

  • DEFAULT_WIDTH: ClassVar[int] = 100
  • DEFAULT_BLUR_RADIUS: ClassVar[int] = 20

Subclass constructors now use the sentinel-default pattern (width: int | None = None, resolved to self.DEFAULT_WIDTH at the point of consumption). Docstrings reference DEFAULT_WIDTH / DEFAULT_BLUR_RADIUS (with the value in parentheses).

This is part of the ongoing constants-audit cleanup (continuation of the pattern established in #1964 and #1965).

Scope

Touched only pyrit/output/:

  • base.py — added DEFAULT_WIDTH and DEFAULT_BLUR_RADIUS ClassVars on PrinterBase.
  • attack_result/pretty.py, attack_result/markdown.py
  • conversation/pretty.py, conversation/markdown.py
  • scenario_result/pretty.py
  • score/pretty.py
  • helpers.pyoutput_attack_async and output_conversation_async now take blur_radius: int | None = None and forward None to the printer (printer sentinels resolve the default).

Notes

  • The kickoff doc mentioned a font_size = 15 default in printer files, but there are no font_size references anywhere in pyrit/output/. (The font_size = 15 hits in the repo are in pyrit/prompt_converter/, out of scope for this PR.) Only DEFAULT_WIDTH and DEFAULT_BLUR_RADIUS are promoted here.
  • All width and blur_radius defaults in pyrit/output/ were already consistent (100 and 20 respectively) — no diverging values to preserve.

No value changes. No behaviour changes.

Verified: ruff check pyrit/output/, ty check pyrit/output/, pytest tests/unit/output/ (173 passed).

Move the hard-coded ``width = 100`` and ``blur_radius = 20`` defaults out
of every printer constructor in ``pyrit/output/`` onto ``PrinterBase`` as
``DEFAULT_WIDTH: ClassVar[int]`` and ``DEFAULT_BLUR_RADIUS: ClassVar[int]``.
Subclass constructors use the sentinel-default pattern
(``width: int | None = None`` resolved via ``self.DEFAULT_*``); ``helpers.py``
forwards ``None`` through and lets the printer resolve the default.

No value changes. No behaviour changes.

Verified: ruff / ty / pytest pyrit/output/.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz

Copy link
Copy Markdown
Contributor Author

Closing per maintainer feedback on the constants-audit work.

This PR introduced the sentinel-default pattern (changing x: T = <literal> into x: T | None = None + if x is None: x = self.DEFAULT_X) which widens the public API signature. The preference is to keep constants inside their owning class (Track A — see #1964, #1965, #1972, #1973, #1974, #1975) but not to promote hard-coded single-use defaults via a None-sentinel.

Branch left intact in case any portion is worth cherry-picking later.

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