Skip to content

Fix hooks printing errors to stderr instead of stdout#1844

Merged
nathanjmcdougall merged 2 commits into
mainfrom
copilot/fix-bug-in-docstring-hook
Apr 7, 2026
Merged

Fix hooks printing errors to stderr instead of stdout#1844
nathanjmcdougall merged 2 commits into
mainfrom
copilot/fix-bug-in-docstring-hook

Conversation

Copilot AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Pre-commit/prek hooks were printing violation output to stderr and a success message to stdout. Since prek captures stdout as the primary display stream, errors could go unseen while "No forbidden patterns found in docstrings." was always the visible output.

Changes

  • hooks/check-docstring-substrings.py, check-comment-keywords.py, check-banned-words.py: Print violations to stdout, remove redundant success messages (the framework already shows Passed/Failed), drop unused sys imports

Before/after

# Before: errors invisible, success message always shown
if violations:
    print("ERROR: ...", file=sys.stderr)  # potentially unseen
    return 1
print("No forbidden patterns found in docstrings.")  # always visible

# After: errors visible, no noise on success
if violations:
    print("ERROR: ...")  # stdout, captured by prek
    return 1
return 0

Lesson

Filed #1845 — pre-commit hooks must use stdout for all output (general CLI convention of errors→stderr conflicts with the pre-commit captured-output model).

…ess messages

The hooks were printing error output to stderr and a success message to
stdout. In a pre-commit/prek context, stdout is the standard output stream
for hook output. Using stderr for errors meant violations could go unseen
while the success message on stdout always appeared.

Changes:
- check-docstring-substrings.py: errors to stdout, removed success msg
- check-comment-keywords.py: errors to stdout, removed success msg
- check-banned-words.py: errors to stdout, removed success msg
- Removed unused sys imports from all three hooks

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/16f73dc6-f9ed-489f-aabd-b89069012a57

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug in forbidden docstring substring hook Fix hooks printing errors to stderr instead of stdout Apr 7, 2026
Copilot AI requested a review from nathanjmcdougall April 7, 2026 06:40
@codecov

codecov Bot commented Apr 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Apr 7, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/fix-bug-in-docstring-hook (4accb13) with main (31a0d16)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (5eb75b1) during the generation of this report, so 31a0d16 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@nathanjmcdougall nathanjmcdougall merged commit acd3d4e into main Apr 7, 2026
10 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/fix-bug-in-docstring-hook branch April 7, 2026 06:58
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.

Fix bug in forbidden docstring substring hook

2 participants