mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-26 07:04:45 +03:00
Typing: Image.save
This commit is contained in:
parent
864e953136
commit
4b47177634
|
@ -1996,15 +1996,16 @@ class Image(object):
|
||||||
|
|
||||||
filename = ""
|
filename = ""
|
||||||
open_fp = False
|
open_fp = False
|
||||||
if isPath(fp):
|
_fp = None # type: BinaryIO
|
||||||
filename = fp
|
if isPath(fp) or (HAS_PATHLIB and isinstance(fp, Path)):
|
||||||
open_fp = True
|
|
||||||
elif HAS_PATHLIB and isinstance(fp, Path):
|
|
||||||
filename = str(fp)
|
filename = str(fp)
|
||||||
open_fp = True
|
open_fp = True
|
||||||
if not filename and hasattr(fp, "name") and isPath(fp.name):
|
else:
|
||||||
|
_fp = fp # type: ignore
|
||||||
|
|
||||||
|
if not filename and hasattr(_fp, "name") and isPath(_fp.name):
|
||||||
# only set the name for metadata purposes
|
# only set the name for metadata purposes
|
||||||
filename = fp.name
|
filename = _fp.name
|
||||||
|
|
||||||
# may mutate self!
|
# may mutate self!
|
||||||
self.load()
|
self.load()
|
||||||
|
@ -2037,14 +2038,14 @@ class Image(object):
|
||||||
if open_fp:
|
if open_fp:
|
||||||
# Open also for reading ("+"), because TIFF save_all
|
# Open also for reading ("+"), because TIFF save_all
|
||||||
# writer needs to go back and edit the written data.
|
# writer needs to go back and edit the written data.
|
||||||
fp = builtins.open(filename, "w+b")
|
_fp = builtins.open(filename, "w+b")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
save_handler(self, fp, filename)
|
save_handler(self, _fp, filename)
|
||||||
finally:
|
finally:
|
||||||
# do what we can to clean up
|
# do what we can to clean up
|
||||||
if open_fp:
|
if open_fp:
|
||||||
fp.close()
|
_fp.close()
|
||||||
|
|
||||||
def seek(self, frame):
|
def seek(self, frame):
|
||||||
# type: (int) -> None
|
# type: (int) -> None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user