https://github.com/python/cpython/commit/0e1dac2000db1432fcd24c13b1b5404d00f1f79c
commit: 0e1dac2000db1432fcd24c13b1b5404d00f1f79c
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: terryjreedy <[email protected]>
date: 2026-10-20T19:50:16Z
summary:

[3.15] gh-139580: Clarify pathlib full_match recursive pattern docs (GH-151479) 
(#159955)

gh-139580: Clarify pathlib full_match recursive pattern docs (GH-151479)

Documents how PurePath.full_match() handles a pattern ending in /**: /a/** 
matches /a/b but not /a, because the separator before ** must be present in the 
path and PurePath drops trailing slashes. Adds two doctest examples under 
full_match() and a note at the ** entry of the pattern language list 
contrasting it with Path.glob().
---------
(cherry picked from commit 264860472c1ec9446974c6c235b26c1774cec75d)

Co-authored-by: Harjoth Khara <[email protected]>
Co-authored-by: Terry J Reedy <[email protected]>

files:
M Doc/library/pathlib.rst

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index f2957de1e9b684..46a5d3320bd19c 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -586,10 +586,23 @@ Pure paths provide the following methods and properties:
       True
       >>> PurePath('a/b.py').full_match('*.py')
       False
-      >>> PurePath('/a/b/c.py').full_match('/a/**')
-      True
       >>> PurePath('/a/b/c.py').full_match('**/*.py')
       True
+      >>> PurePath('/a/b/c.py').full_match('/a/**')
+      True
+
+   Patterns ending in "``/**``", as in the example above, may surprise when
+   passed to ``full_match``. Even though "``**``" can match 0 segments,
+   "``.../**``" requires a separator to match. Hence "``/a/**``" does not
+   match path "``/a``". Since :class:`PurePath` drops trailing slashes, this
+   pattern also does not match "``/a/``".
+
+   ::
+
+      >>> PurePath('/a').full_match('/a/**')
+      False
+      >>> PurePath('/a/').full_match('/a/**')
+      False
 
    .. seealso::
       :ref:`pathlib-pattern-language` documentation.
@@ -1810,6 +1823,8 @@ The following wildcards are supported in patterns for
 
 ``**`` (entire segment)
   Matches any number of file or directory segments, including zero.
+  Note that in :meth:`~PurePath.full_match`, "``a/**``" does not match
+  "``a``", whereas :meth:`~Path.glob` yields "``a``" for that pattern.
 ``*`` (entire segment)
   Matches one file or directory segment.
 ``*`` (part of a segment)

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to