Skip to content

AI junk - #3753

Closed
harsh-404-404 wants to merge 2 commits into
pallets:mainfrom
harsh-404-404:fix-windows-pager-typeerror
Closed

AI junk#3753
harsh-404-404 wants to merge 2 commits into
pallets:mainfrom
harsh-404-404:fix-windows-pager-typeerror

Conversation

@harsh-404-404

Copy link
Copy Markdown

On branch fix-windows-pager-typeerror
Changes to be committed:
modified: src/click/_termui_impl.py

Fixes a TypeError and subsequent [WinError 32] when using click.echo_via_pager() on Windows.

The Bug:
The _tempfilepager yields a binary file (mode="wb"), but echo_via_pager expects a TextIO stream and writes strings to it.

The Domino Effect:

  1. Writing a string to the "wb" file throws a TypeError.
  2. Because this exception happens before f.close(), the temporary file is left open by Python.
  3. The finally block attempts os.unlink() on an open file, which Windows rejects, throwing [WinError 32].

The Fix:
Changed the NamedTemporaryFile mode to "w" with explicit encoding, and yielded it as TextIO to match the expected signature in echo_via_pager.

(Note: I did not open an issue prior to this PR as the type mismatch was straightforward.

Regarding Tests:
I did not include an automated test because mocking the Windows Terminal and pager subprocesses in the test suite is a bit tricky, and I'm a first-time contributor. However, the problem is very apparent and easily reproducible.

If you run the following script on Windows 11 using Click 8.4.2, it crashes immediately with a TypeError (and subsequently [WinError 32]). With my patch applied, it opens the pager and exits cleanly.

import click

# Generate enough text to force the pager to actually open
large_text = "\n".join([f"This is line number {i}" for i in range(1000)])

print("Opening pager... Press 'q' to quit once it opens.")

# This triggers the TypeError on Windows in 8.4.2
click.echo_via_pager(large_text)

print("If you see this, it didn't crash!")

harsh-404-404 added 2 commits August 8, 2026 18:14
with '#' will be ignored, and an empty message aborts the commit.

On branch fix-windows-pager-typeerror
Your branch is up to date with 'origin/fix-windows-pager-typeerror'.

Changes to be committed:
	modified:   CHANGES.md
	modified:   src/click/_termui_impl.py
with '#' will be ignored, and an empty message aborts the commit.

On branch fix-windows-pager-typeerror
Your branch is up to date with 'origin/fix-windows-pager-typeerror'.

Changes to be committed:
	modified:   CHANGES.md
@davidism davidism closed this Aug 8, 2026
@kdeldycke kdeldycke added windows Windows-specific behavior rejected AI Contribution rejected because of its untrustworthy AI origin and removed windows Windows-specific behavior labels Aug 8, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 23, 2026
@davidism davidism changed the title Fix TypeError and WinError 32 in Windows tempfile pager AI junk Aug 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

rejected AI Contribution rejected because of its untrustworthy AI origin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] On Windows, get_pager_file returns a typing.BinaryIO object NOT typing.TextIO echo_via_pager broken on Windows since 8.4.0

3 participants