From df85946e8a5586b6dc4f242d7fa24ea04a2044f8 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 6 Jan 2016 11:15:52 -0800 Subject: [PATCH 1/3] Docs for issue #22570. --- Doc/library/pathlib.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 24e2a308dfe..05c5d722ef7 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -365,6 +365,23 @@ Pure paths provide the following methods and properties: '' +.. data:: PurePath.path + + A string representing the full path:: + + >>> PurePosixPath('my/library/setup.py').path + 'my/library/setup.py' + + This always returns the same value as ``str(p)``; it is included to + serve as a one-off protocol. Code that wants to support both + strings and ``pathlib.Path`` objects as filenames can write + ``arg = getattr(arg, 'path', arg)`` to get the path as a string. + This can then be passed to various system calls or library + functions that expect a string. Unlike the alternative + ``arg = str(arg)``, this will still raise an exception if an object + of some other type is given by accident. + + .. data:: PurePath.suffix The file extension of the final component, if any:: From b1360543e53b36e1a6833fee47caeeaea40aa26a Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 6 Jan 2016 11:23:31 -0800 Subject: [PATCH 2/3] Add versionadded (3.4.5) to docs for issue #22570. --- Doc/library/pathlib.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 05c5d722ef7..cb066bdc094 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -381,6 +381,7 @@ Pure paths provide the following methods and properties: ``arg = str(arg)``, this will still raise an exception if an object of some other type is given by accident. + .. versionadded:: 3.4.5 .. data:: PurePath.suffix From 1469d744bccbf7c6357bd23f06851d70f538f7e6 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 6 Jan 2016 11:36:03 -0800 Subject: [PATCH 3/3] Cross-reference os.DirEntry and pathlib.Path for issue #22570. --- Doc/library/os.rst | 6 ++++++ Doc/library/pathlib.rst | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 144d9b24c8e..dcdc4ec0eaa 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -2035,6 +2035,12 @@ features: The result is cached on the ``DirEntry`` object. Call :func:`os.stat` to fetch up-to-date information. + Note that there is a nice correspondence between several attributes + and methods of ``DirEntry`` and of :class:`pathlib.Path`. In + particular, the ``name`` and ``path`` attributes have the same + meaning, as do the ``is_dir()``, ``is_file()``, ``is_symlink()`` + and ``stat()`` methods. + .. versionadded:: 3.5 diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 9c8ca58b33f..a7ce18df336 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -381,7 +381,11 @@ Pure paths provide the following methods and properties: ``arg = str(arg)``, this will still raise an exception if an object of some other type is given by accident. + A nice advantage is that this protocol is also supported by + :class:`os.DirEntry` objects returned by :func:`os.scandir`. + .. versionadded:: 3.4.5 + .. versionadded:: 3.5.2 .. data:: PurePath.suffix