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

Fixed bug when saving to a non-existent path using pathlib #1748

Merged
merged 1 commit into from
Mar 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ def save(self, fp, format=None, **params):
elif sys.version_info >= (3, 4):
from pathlib import Path
if isinstance(fp, Path):
filename = str(fp.resolve())
filename = str(fp)
open_fp = True
elif hasattr(fp, "name") and isPath(fp.name):
# only set the name for metadata purposes
Expand Down
6 changes: 6 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from helper import unittest, PillowTestCase, hopper

from PIL import Image
import os
import sys


Expand Down Expand Up @@ -57,6 +58,11 @@ def test_pathlib(self):
self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (128, 128))

temp_file = self.tempfile("temp.jpg")
if os.path.exists(temp_file):
os.remove(temp_file)
im.save(Path(temp_file))

def test_tempfile(self):
# see #1460, pathlib support breaks tempfile.TemporaryFile on py27
# Will error out on save on 3.0.0
Expand Down