Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-123345: improve fnmatch docs #123346

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Doc/library/fnmatch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ module. See module :mod:`glob` for pathname expansion (:mod:`glob` uses
a period are not special for this module, and are matched by the ``*`` and ``?``
patterns.

Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used to
cache the compiled regex patterns in the following functions: :func:`fnmatch`,
:func:`fnmatchcase`, :func:`.filter`.
Unless stated otherwise, "filename string" and "pattern string" either refer to
barneygale marked this conversation as resolved.
Show resolved Hide resolved
:class:`str` or ``ISO-8859-1`` encoded :class:`bytes` objects. Note that the
functions documented below do not allow to mix a :class:`!bytes` pattern with
a :class:`!str` filename, and vice-versa.

Finally, note that :func:`functools.lru_cache` with a *maxsize* of 32768
is used to cache the (typed) compiled regex patterns in the following
functions: :func:`fnmatch`, :func:`fnmatchcase`, :func:`.filter`.


.. function:: fnmatch(name, pat)

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

.. function:: filter(names, pat)

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


.. function:: translate(pat)

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

Example:

Expand Down
Loading