4040import warnings
4141from collections .abc import Callable , MutableMapping
4242from enum import IntEnum
43- from pathlib import Path
4443from types import ModuleType
4544from typing import IO , TYPE_CHECKING , Any
4645
@@ -2383,7 +2382,7 @@ def save(self, fp, format=None, **params) -> None:
23832382 implement the ``seek``, ``tell``, and ``write``
23842383 methods, and be opened in binary mode.
23852384
2386- :param fp: A filename (string), pathlib.Path object or file object.
2385+ :param fp: A filename (string), os.PathLike object or file object.
23872386 :param format: Optional format override. If omitted, the
23882387 format to use is determined from the filename extension.
23892388 If a file object was used instead of a filename, this
@@ -2398,11 +2397,8 @@ def save(self, fp, format=None, **params) -> None:
23982397
23992398 filename : str | bytes = ""
24002399 open_fp = False
2401- if isinstance (fp , Path ):
2402- filename = str (fp )
2403- open_fp = True
2404- elif isinstance (fp , (str , bytes )):
2405- filename = fp
2400+ if is_path (fp ):
2401+ filename = os .path .realpath (os .fspath (fp ))
24062402 open_fp = True
24072403 elif fp == sys .stdout :
24082404 try :
@@ -3225,7 +3221,7 @@ def open(fp, mode="r", formats=None) -> Image:
32253221 :py:meth:`~PIL.Image.Image.load` method). See
32263222 :py:func:`~PIL.Image.new`. See :ref:`file-handling`.
32273223
3228- :param fp: A filename (string), pathlib.Path object or a file object.
3224+ :param fp: A filename (string), os.PathLike object or a file object.
32293225 The file object must implement ``file.read``,
32303226 ``file.seek``, and ``file.tell`` methods,
32313227 and be opened in binary mode. The file object will also seek to zero
0 commit comments