44import inspect
55import io
66import itertools
7+ import os
78import re
89import sys
910import typing as t
@@ -837,7 +838,10 @@ def edit(
837838 env : cabc .Mapping [str , str ] | None = None ,
838839 require_save : bool = True ,
839840 extension : str = ".txt" ,
840- filename : str | cabc .Iterable [str ] | None = None ,
841+ filename : str
842+ | os .PathLike [str ]
843+ | cabc .Iterable [str | os .PathLike [str ]]
844+ | None = None ,
841845) -> None : ...
842846
843847
@@ -847,7 +851,10 @@ def edit(
847851 env : cabc .Mapping [str , str ] | None = None ,
848852 require_save : bool = True ,
849853 extension : str = ".txt" ,
850- filename : str | cabc .Iterable [str ] | None = None ,
854+ filename : str
855+ | os .PathLike [str ]
856+ | cabc .Iterable [str | os .PathLike [str ]]
857+ | None = None ,
851858) -> str | bytes | bytearray | None :
852859 r"""Edits the given text in the defined editor. If an editor is given
853860 (should be the full path to the executable but the regular operating
@@ -874,16 +881,20 @@ def edit(
874881 highlighting.
875882 :param filename: if provided it will edit this file instead of the
876883 provided text contents. It will not use a temporary
877- file as an indirection in that case. If the editor supports
878- editing multiple files at once, a sequence of files may be
879- passed as well. Invoke `click.file` once per file instead
880- if multiple files cannot be managed at once or editing the
881- files serially is desired.
884+ file as an indirection in that case. It accepts a path
885+ or any iterable of paths. If the editor supports
886+ editing multiple files at once, a sequence of files may
887+ be passed as well. Invoke `click.file` once per file
888+ instead if multiple files cannot be managed at once or
889+ editing the files serially is desired.
882890
883891 .. versionchanged:: 8.2.0
884892 ``filename`` now accepts any ``Iterable[str]`` in addition to a ``str``
885893 if the ``editor`` supports editing multiple files at once.
886894
895+ .. versionchanged:: 8.5.0
896+ ``filename`` accepts ``os.PathLike`` values in addition to strings.
897+
887898 """
888899 from ._termui_impl import Editor
889900
@@ -892,7 +903,7 @@ def edit(
892903 if filename is None :
893904 return ed .edit (text )
894905
895- if isinstance (filename , str ):
906+ if isinstance (filename , ( str , os . PathLike ) ):
896907 filename = (filename ,)
897908
898909 ed .edit_files (filenames = filename )
0 commit comments