Skip to content

Commit 3c535a0

Browse files
miss-islingtonharjothkharaterryjreedy
authored
[3.14] gh-139580: Clarify pathlib full_match recursive pattern docs (GH-151479) (#159956)
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 2648604) Co-authored-by: Harjoth Khara <harjoth.khara@gmail.com> Co-authored-by: Terry J Reedy <tjreedy@udel.edu>
1 parent 5eed22f commit 3c535a0

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎Doc/library/pathlib.rst‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,23 @@ Pure paths provide the following methods and properties:
600600
True
601601
>>> PurePath('a/b.py').full_match('*.py')
602602
False
603-
>>> PurePath('/a/b/c.py').full_match('/a/**')
604-
True
605603
>>> PurePath('/a/b/c.py').full_match('**/*.py')
606604
True
605+
>>> PurePath('/a/b/c.py').full_match('/a/**')
606+
True
607+
608+
Patterns ending in "``/**``", as in the example above, may surprise when
609+
passed to ``full_match``. Even though "``**``" can match 0 segments,
610+
"``.../**``" requires a separator to match. Hence "``/a/**``" does not
611+
match path "``/a``". Since :class:`PurePath` drops trailing slashes, this
612+
pattern also does not match "``/a/``".
613+
614+
::
615+
616+
>>> PurePath('/a').full_match('/a/**')
617+
False
618+
>>> PurePath('/a/').full_match('/a/**')
619+
False
607620

608621
.. seealso::
609622
:ref:`pathlib-pattern-language` documentation.
@@ -1814,6 +1827,8 @@ The following wildcards are supported in patterns for
18141827

18151828
``**`` (entire segment)
18161829
Matches any number of file or directory segments, including zero.
1830+
Note that in :meth:`~PurePath.full_match`, "``a/**``" does not match
1831+
"``a``", whereas :meth:`~Path.glob` yields "``a``" for that pattern.
18171832
``*`` (entire segment)
18181833
Matches one file or directory segment.
18191834
``*`` (part of a segment)

0 commit comments

Comments
 (0)