Skip to content

Commit

Permalink
Merge pull request #5633 from radarhere/save_path
Browse files Browse the repository at this point in the history
Corrected pathlib.Path detection when saving
  • Loading branch information
hugovk committed Aug 6, 2021
2 parents 6798c87 + 4038a28 commit 2e5ce83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions Tests/test_image.py
Expand Up @@ -149,10 +149,11 @@ def test_pathlib(self, tmp_path):
assert im.mode == "RGB"
assert im.size == (128, 128)

temp_file = str(tmp_path / "temp.jpg")
if os.path.exists(temp_file):
os.remove(temp_file)
im.save(Path(temp_file))
for ext in (".jpg", ".jp2"):
temp_file = str(tmp_path / ("temp." + ext))
if os.path.exists(temp_file):
os.remove(temp_file)
im.save(Path(temp_file))

def test_fp_name(self, tmp_path):
temp_file = str(tmp_path / "temp.jpg")
Expand Down
8 changes: 4 additions & 4 deletions src/PIL/Image.py
Expand Up @@ -2180,12 +2180,12 @@ def save(self, fp, format=None, **params):

filename = ""
open_fp = False
if isPath(fp):
filename = fp
open_fp = True
elif isinstance(fp, Path):
if isinstance(fp, Path):
filename = str(fp)
open_fp = True
elif isPath(fp):
filename = fp
open_fp = True
elif fp == sys.stdout:
try:
fp = sys.stdout.buffer
Expand Down

0 comments on commit 2e5ce83

Please sign in to comment.