Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c28592b

Browse files
committed
Issue #27186: Define what a "path-like object" is.
Thanks to Dusty Phillips for the initial patch.
1 parent c78ca1e commit c28592b

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

Doc/glossary.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,16 @@ Glossary
778778
One of the default :term:`meta path finders <meta path finder>` which
779779
searches an :term:`import path` for modules.
780780

781+
path-like object
782+
An object representing a file system path. A path-like object is either
783+
a :class:`str` or :class:`bytes` object representing a path, or an object
784+
implementing the :class:`os.PathLike` protocol. An object that supports
785+
the :class:`os.PathLike` protocol can be converted to a :class:`str` or
786+
:class:`bytes` file system path by calling the :func:`os.fspath` function;
787+
:func:`os.fsdecode` and :func:`os.fsencode` can be used to guarantee a
788+
:class:`str` or :class:`bytes` result instead, respectively. Introduced
789+
by :pep:`519`.
790+
781791
portion
782792
A set of files in a single directory (possibly stored in a zip file)
783793
that contribute to a namespace package, as defined in :pep:`420`.

Doc/library/os.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ process and user.
171171

172172
.. function:: fsencode(filename)
173173

174-
Encode *filename* to the filesystem encoding with ``'surrogateescape'``
175-
error handler, or ``'strict'`` on Windows; return :class:`bytes` unchanged.
174+
Encode :term:`path-like <path-like object>` *filename* to the filesystem
175+
encoding with ``'surrogateescape'`` error handler, or ``'strict'`` on
176+
Windows; return :class:`bytes` unchanged.
176177

177178
:func:`fsdecode` is the reverse function.
178179

@@ -185,8 +186,9 @@ process and user.
185186

186187
.. function:: fsdecode(filename)
187188

188-
Decode *filename* from the filesystem encoding with ``'surrogateescape'``
189-
error handler, or ``'strict'`` on Windows; return :class:`str` unchanged.
189+
Decode the :term:`path-like <path-like object>` *filename* from the
190+
filesystem encoding with ``'surrogateescape'`` error handler, or ``'strict'``
191+
on Windows; return :class:`str` unchanged.
190192

191193
:func:`fsencode` is the reverse function.
192194

@@ -2003,8 +2005,8 @@ features:
20032005
control over errors, you can catch :exc:`OSError` when calling one of the
20042006
``DirEntry`` methods and handle as appropriate.
20052007

2006-
To be directly usable as a path-like object, ``DirEntry`` implements the
2007-
:class:`os.PathLike` interface.
2008+
To be directly usable as a :term:`path-like object`, ``DirEntry`` implements
2009+
the :class:`os.PathLike` interface.
20082010

20092011
Attributes and methods on a ``DirEntry`` instance are as follows:
20102012

@@ -2112,7 +2114,7 @@ features:
21122114

21132115
Note that there is a nice correspondence between several attributes
21142116
and methods of ``DirEntry`` and of :class:`pathlib.Path`. In
2115-
particular, the ``name`` and ``path`` attributes have the same
2117+
particular, the ``name`` attribute has the same
21162118
meaning, as do the ``is_dir()``, ``is_file()``, ``is_symlink()``
21172119
and ``stat()`` methods.
21182120

0 commit comments

Comments
 (0)