8000 GH-101112: Add "pattern language" section to pathlib docs by barneygale · Pull Request #114030 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-101112: Add "pattern language" section to pathlib docs #114030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 26, 2024
Prev Previous commit
Next Next commit
Address review feedback
  • Loading branch information
barneygale committed Feb 25, 2024
commit d7e6ed1495768f2bd408fe7bfc72eb5c4533b5db
28 changes: 14 additions & 14 deletions Doc/library/pathlib.rst
< 659B tr data-hunk="7f81fa09b501ce0c752bc5b9e83b53faee39c9dfc4f3bc600ee93734ef1c4076" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ Pure paths provide the following methods and properties:
True

.. seealso::
:ref:`pattern-language` documentation.
:ref:`pathlib-pattern-language` documentation.

As with other methods, case-sensitivity follows platform defaults::

Expand Down Expand Up @@ -1002,7 +1002,7 @@ call fails (for example because the path doesn't exist).
PosixPath('test_pathlib.py')]

.. seealso::
:ref:`pattern-language` documentation.
:ref:`pathlib-pattern-language` documentation.

This method calls :meth:`Path.is_dir` on the top-level directory and
propagates any :exc:`OSError` exception that is raised. Subsequent
8000 Expand Down Expand Up @@ -1040,7 +1040,7 @@ call fails (for example because the path doesn't exist).
:func:`Path.glob` with "``**/``" added in front of the *pattern*.

.. seealso::
:ref:`pattern-language` and :meth:`Path.glob` documentation.
:ref:`pathlib-pattern-language` and :meth:`Path.glob` documentation.

.. audit-event:: pathlib.Path.rglob self,pattern pathlib.Path.rglob

Expand Down Expand Up @@ -1612,19 +1612,19 @@ call fails (for example because the path doesn't exist).
The *newline* parameter was added.


.. _pattern-language:
.. _pathlib-pattern-language:

Pattern language
----------------

The following wildcards are supported in patterns for
:meth:`~PurePath.full_match`, :meth:`~Path.glob` and :meth:`~Path.rglob`:

``**`` (full segment)
Matches any number of file or directory segments.
``*`` (full segment)
``**`` (entire segment)
Matches any number of file or directory segments, including zero.
``*`` (entire segment)
Matches one file or directory segment.
``*`` (otherwise)
``*`` (part of a segment)
Matches any number of non-separator characters.
``?``
Matches one non-separator character.
Expand Down Expand Up @@ -1669,13 +1669,13 @@ Comparison to the :mod:`glob` module
The patterns accepted and results generated by :meth:`~Path.glob` and
:meth:`~Path.rglob` differ slightly from those by the :mod:`glob` module:

1. Hidden files (beginning with a dot) are not special in pathlib. This is
1. Files beginning with a dot are not special in pathlib. This is
like passing ``include_hidden=True`` to :func:`glob.glob`.
2. "``**``" components are always recursive in pathlib. This is like passing
``recursive=True`` to :func:`glob.glob`.
3. "``**``" components do not follow symlinks by default in pathlib. Pass
``follow_symlinks=True`` to :meth:`Path.glob` for :func:`glob.glob`-like
behaviour.
2. "``**``" pattern components are always recursive in pathlib. This is like
passing ``recursive=True`` to :func:`glob.glob`.
3. "``**``" pattern components do not follow symlinks by default in pathlib.
Pass ``follow_symlinks=True`` to :meth:`Path.glob` for
:func:`glob.glob`-like behaviour.
4. Like all :class:`PurePath` and :class:`Path` objects, the values returned
from :meth:`Path.glob` and :meth:`~Path.rglob` don't include trailing
slashes.
Expand Down
0