Skip to content

Conversation

@radarhere
Copy link
Member

This PR uses monkeypatch rather than the current behaviour of setting and restoring sys.stdout.

old_stdout = sys.stdout
class MyStdOut:
buffer = BytesIO()
mystdout: MyStdOut | BytesIO = MyStdOut() if buffer else BytesIO()
sys.stdout = mystdout
with Image.open(TEST_PNG_FILE) as im:
im.save(sys.stdout, "PNG")
# Reset stdout
sys.stdout = old_stdout

@hugovk hugovk merged commit e8dad19 into python-pillow:main Dec 28, 2024
48 checks passed
@radarhere radarhere deleted the monkeypatch branch December 28, 2024 09:44
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