Skip to content

refactor: use shared PRINTER singleton#5329

Merged
greysonlalonde merged 5 commits into
mainfrom
refactor/use-printer-singleton
Apr 7, 2026
Merged

refactor: use shared PRINTER singleton#5329
greysonlalonde merged 5 commits into
mainfrom
refactor/use-printer-singleton

Conversation

@greysonlalonde

@greysonlalonde greysonlalonde commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace all Printer() instantiations and _printer attributes/variables with the shared PRINTER singleton from utilities/printer.py
  • Remove unnecessary PrivateAttr declarations, module-level variables, and ClassVar for Printer across 22 files
  • Net deletion of 36 lines

Test plan

  • All pre-commit hooks pass (ruff, ruff-format, mypy)
  • Existing test suite passes unchanged

Note

Low Risk
Broad but mechanical refactor across executors/hooks/CLI to centralize printing; low functional risk, with main concern being any code that relied on per-instance printer state or test patching paths.

Overview
Standardizes console output by introducing a module-level PRINTER singleton in utilities/printer.py and migrating call sites to use it instead of constructing Printer() instances or storing _printer/_printer globals.

This removes multiple Printer attributes/PrivateAttr/ClassVar fields and updates error/verbose logging paths in executors, hooks, CLI commands, flow persistence/utils, and tool/LLM handling to pass PRINTER through to helper functions. Tests were adjusted to patch/mock PRINTER rather than mutating instance printers.

Reviewed by Cursor Bugbot for commit 22f02e7. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added the size/L label Apr 7, 2026

@iris-clawd iris-clawd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: PRINTER singleton

Clean mechanical refactor. 22 files, net -37 lines, all Printer() / _printer / PrivateAttr(default_factory=Printer) replaced with PRINTER singleton.

✅ Approve

  • Printer is stateless (just wraps print() with ANSI colors), so a singleton is the correct pattern — no shared mutable state concerns.
  • Removes unnecessary PrivateAttr, ClassVar, and module-level _printer = Printer() instances across the codebase.
  • Import path is consistent: from crewai.utilities.printer import PRINTER everywhere.
  • Printer class is still exported for the few places that pass it as a parameter (e.g., handle_unknown_error(printer, ...)) — good, no breaking changes to function signatures.

No concerns. Ship it. ✅ 💬 177

@iris-clawd iris-clawd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving after new commits. ✅

@iris-clawd iris-clawd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving. ✅

@iris-clawd iris-clawd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greysonlalonde greysonlalonde merged commit 0450d06 into main Apr 7, 2026
49 checks passed
@greysonlalonde greysonlalonde deleted the refactor/use-printer-singleton branch April 7, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants