Skip to content

Commit 05bd6cb

Browse files
[3.13] pythongh-123345: improve fnmatch docs (pythonGH-123346) (python#128776)
pythongh-123345: improve `fnmatch` docs (pythonGH-123346) (cherry picked from commit 29fe807) Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 33c0ba0 commit 05bd6cb

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Diff for: Doc/library/fnmatch.rst

+12-6
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,15 @@ module. See module :mod:`glob` for pathname expansion (:mod:`glob` uses
4646
a period are not special for this module, and are matched by the ``*`` and ``?``
4747
patterns.
4848

49-
Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used to
50-
cache the compiled regex patterns in the following functions: :func:`fnmatch`,
51-
:func:`fnmatchcase`, :func:`.filter`.
49+
Unless stated otherwise, "filename string" and "pattern string" either refer to
50+
:class:`str` or ``ISO-8859-1`` encoded :class:`bytes` objects. Note that the
51+
functions documented below do not allow to mix a :class:`!bytes` pattern with
52+
a :class:`!str` filename, and vice-versa.
53+
54+
Finally, note that :func:`functools.lru_cache` with a *maxsize* of 32768
55+
is used to cache the (typed) compiled regex patterns in the following
56+
functions: :func:`fnmatch`, :func:`fnmatchcase`, :func:`.filter`.
57+
5258

5359
.. function:: fnmatch(name, pat)
5460

@@ -78,16 +84,16 @@ cache the compiled regex patterns in the following functions: :func:`fnmatch`,
7884

7985
.. function:: filter(names, pat)
8086

81-
Construct a list from those elements of the :term:`iterable` *names*
82-
that match pattern *pat*.
87+
Construct a list from those elements of the :term:`iterable` of filename
88+
strings *names* that match the pattern string *pat*.
8389
It is the same as ``[n for n in names if fnmatch(n, pat)]``,
8490
but implemented more efficiently.
8591

8692

8793
.. function:: translate(pat)
8894

8995
Return the shell-style pattern *pat* converted to a regular expression for
90-
using with :func:`re.match`.
96+
using with :func:`re.match`. The pattern is expected to be a :class:`str`.
9197

9298
Example:
9399

0 commit comments

Comments
 (0)