Skip to content

Commit 19aabd9

Browse files
committed
Check if sys.stdout is a TextIOWrapper instance
1 parent d42e78d commit 19aabd9

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

src/PIL/Image.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,11 +2639,8 @@ def save(
26392639
if is_path(fp):
26402640
filename = os.fspath(fp)
26412641
open_fp = True
2642-
elif fp == sys.stdout:
2643-
try:
2644-
fp = sys.stdout.buffer
2645-
except AttributeError:
2646-
pass
2642+
elif fp == sys.stdout and isinstance(sys.stdout, io.TextIOWrapper):
2643+
fp = sys.stdout.buffer
26472644
if not filename and hasattr(fp, "name") and is_path(fp.name):
26482645
# only set the name for metadata purposes
26492646
filename = os.fspath(fp.name)

0 commit comments

Comments
 (0)