Skip to content

Commit 303854b

Browse files
harjothkharaclaude
andcommitted
gh-139580: Clarify pathlib full_match recursive pattern docs
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a700732 commit 303854b

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

Doc/library/pathlib.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,21 @@ Pure paths provide the following methods and properties:
575575
>>> PurePath('/a/b/c.py').full_match('**/*.py')
576576
True
577577

578+
A pattern ending with "``/**``" matches any path that begins with the
579+
pattern's prefix followed by a separator. For example "``/a/**``" matches
580+
"``/a/b``" and "``/a/b/c``", but not "``/a``", because "``/a``" does not
581+
begin with "``/a/``". The recursive wildcard "``**``" can match zero
582+
segments, but the separator before it must still be present in the path,
583+
and :class:`PurePath` objects do not preserve trailing slashes (so
584+
"``/a/``" is normalized to "``/a``")::
585+
586+
>>> PurePath('/a/b').full_match('/a/**')
587+
True
588+
>>> PurePath('/a').full_match('/a/**')
589+
False
590+
>>> PurePath('/a/').full_match('/a/**')
591+
False
592+
578593
.. seealso::
579594
:ref:`pathlib-pattern-language` documentation.
580595

@@ -1795,7 +1810,10 @@ The following wildcards are supported in patterns for
17951810
:meth:`~PurePath.full_match`, :meth:`~Path.glob` and :meth:`~Path.rglob`:
17961811

17971812
``**`` (entire segment)
1798-
Matches any number of file or directory segments, including zero.
1813+
Matches any number of file or directory segments, including zero. Note that
1814+
in :meth:`~PurePath.full_match`, a pattern ending with "``/**``" requires the
1815+
separator before "``**``" to be present in the path; see that method for an
1816+
example.
17991817
``*`` (entire segment)
18001818
Matches one file or directory segment.
18011819
``*`` (part of a segment)

0 commit comments

Comments
 (0)