Skip to content

Commit 0e1dac2

Browse files
miss-islingtonharjothkharaterryjreedy
authored
[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 2648604) Co-authored-by: Harjoth Khara <harjoth.khara@gmail.com> Co-authored-by: Terry J Reedy <tjreedy@udel.edu>
1 parent 4250c67 commit 0e1dac2

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
@@ -586,10 +586,23 @@ Pure paths provide the following methods and properties:
586586
True
587587
>>> PurePath('a/b.py').full_match('*.py')
588588
False
589-
>>> PurePath('/a/b/c.py').full_match('/a/**')
590-
True
591589
>>> PurePath('/a/b/c.py').full_match('**/*.py')
592590
True
591+
>>> PurePath('/a/b/c.py').full_match('/a/**')
592+
True
593+
594+
Patterns ending in "``/**``", as in the example above, may surprise when
595+
passed to ``full_match``. Even though "``**``" can match 0 segments,
596+
"``.../**``" requires a separator to match. Hence "``/a/**``" does not
597+
match path "``/a``". Since :class:`PurePath` drops trailing slashes, this
598+
pattern also does not match "``/a/``".
599+
600+
::
601+
602+
>>> PurePath('/a').full_match('/a/**')
603+
False
604+
>>> PurePath('/a/').full_match('/a/**')
605+
False
593606

594607
.. seealso::
595608
:ref:`pathlib-pattern-language` documentation.
@@ -1810,6 +1823,8 @@ The following wildcards are supported in patterns for
18101823

18111824
``**`` (entire segment)
18121825
Matches any number of file or directory segments, including zero.
1826+
Note that in :meth:`~PurePath.full_match`, "``a/**``" does not match
1827+
"``a``", whereas :meth:`~Path.glob` yields "``a``" for that pattern.
18131828
``*`` (entire segment)
18141829
Matches one file or directory segment.
18151830
``*`` (part of a segment)

0 commit comments

Comments
 (0)