Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not prematurely return in ImageFile when saving to stdout #5665

Merged
merged 4 commits into from Nov 25, 2021

Conversation

infmagic2047
Copy link
Contributor

@infmagic2047 infmagic2047 commented Aug 9, 2021

Fixes #5657.

The removed block of code is bad for the following reasons:

  1. The return statement makes the function write nothing when fp is stdout, which is obviously unwanted.
  2. The fp.flush() statement is duplicate of the line below, and is therefore useless.

@radarhere
Copy link
Member

@radarhere radarhere commented Aug 9, 2021

When I try this, it doesn't fix the issue for me. Could you add a test to demonstrate?

@infmagic2047
Copy link
Contributor Author

@infmagic2047 infmagic2047 commented Aug 10, 2021

Added tests for JPEG and PPM formats.

Tests/test_file_ppm.py Outdated Show resolved Hide resolved
Tests/test_file_jpeg.py Outdated Show resolved Hide resolved
@radarhere
Copy link
Member

@radarhere radarhere commented Nov 25, 2021

This is reverting part of #1365. That PR added return to prevent the encoder writing bytes to sys.stdout.

Looking back now, I think that was incorrect for this reason, that it did prevent the body of the image from being output.

@radarhere radarhere changed the title Remove stdout check in ImageFile._save Do not return in ImageFile when saving to stdout Nov 25, 2021
@radarhere radarhere merged commit ab6efcb into python-pillow:main Nov 25, 2021
48 of 49 checks passed
@radarhere radarhere changed the title Do not return in ImageFile when saving to stdout Do not prematurely return in ImageFile when saving to stdout Nov 25, 2021
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.

2 participants