Skip to content

gh-94220: Align fnmatch docs with the implementation and amend markup #114152

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

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Changes from all 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
26 changes: 14 additions & 12 deletions Doc/library/fnmatch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used t
cache the compiled regex patterns in the following functions: :func:`fnmatch`,
:func:`fnmatchcase`, :func:`.filter`.

.. function:: fnmatch(filename, pattern)
.. function:: fnmatch(name, pat)

Test whether the *filename* string matches the *pattern* string, returning
:const:`True` or :const:`False`. Both parameters are case-normalized
Test whether the filename string *name* matches the pattern string *pat*,
returning ``True`` or ``False``. Both parameters are case-normalized
using :func:`os.path.normcase`. :func:`fnmatchcase` can be used to perform a
case-sensitive comparison, regardless of whether that's standard for the
operating system.
Expand All @@ -69,22 +69,24 @@ cache the compiled regex patterns in the following functions: :func:`fnmatch`,
print(file)


.. function:: fnmatchcase(filename, pattern)
.. function:: fnmatchcase(name, pat)

Test whether *filename* matches *pattern*, returning :const:`True` or
:const:`False`; the comparison is case-sensitive and does not apply
:func:`os.path.normcase`.
Test whether the filename string *name* matches the pattern string *pat*,
returning ``True`` or ``False``;
the comparison is case-sensitive and does not apply :func:`os.path.normcase`.


.. function:: filter(names, pattern)
.. function:: filter(names, pat)

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


.. function:: translate(pattern)
.. function:: translate(pat)

Return the shell-style *pattern* converted to a regular expression for
Return the shell-style pattern *pat* converted to a regular expression for
using with :func:`re.match`.

Example:
Expand Down