Skip to content

Commit bd3c951

Browse files
committed
Soft deprecate re.match and re.Pattern.match in favour of prefixmatch
1 parent 82aaef0 commit bd3c951

File tree

5 files changed

+71
-13
lines changed

5 files changed

+71
-13
lines changed

Doc/deprecations/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Deprecations
1515

1616
.. include:: pending-removal-in-future.rst
1717

18+
.. include:: soft-deprecations.rst
19+
1820
C API deprecations
1921
------------------
2022

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Soft deprecations
2+
-----------------
3+
4+
There are no plans to remove :term:`soft deprecated` APIs.
5+
6+
* :func:`re.match` and :meth:`re.Pattern.match` are now
7+
:term:`soft deprecated` in favor of the new :func:`re.prefixmatch` and
8+
:meth:`re.Pattern.prefixmatch` APIs, which have been added as alternate,
9+
more explicit names. These are intended to be used to alleviate confusion
10+
around what *match* means by following the Zen of Python's *"Explicit is
11+
better than implicit"* mantra. Most other language regular expression
12+
libraries use an API named *match* to mean what Python has always called
13+
*search*.
14+
15+
We **do not** plan to remove the older :func:`!match` name, as it has been
16+
used in code for over 30 years. Code supporting older versions of Python
17+
should continue to use :func:`!match`, while new code should prefer
18+
:func:`!prefixmatch`. See :ref:`prefixmatch-vs-match`.
19+
20+
(Contributed by Gregory P. Smith in :gh:`86519` and
21+
Hugo van Kemenade in :gh:`148100`.)

Doc/library/re.rst

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -954,9 +954,10 @@ Functions
954954
:func:`~re.match`. Use that name when you need to retain compatibility with
955955
older Python versions.
956956

957-
.. versionchanged:: 3.15
958-
The alternate :func:`~re.prefixmatch` name of this API was added as a
959-
more explicitly descriptive name than :func:`~re.match`. Use it to better
957+
.. deprecated:: 3.15
958+
:func:`~re.match` has been :term:`soft deprecated` in favor of
959+
the alternate :func:`~re.prefixmatch` name of this API which is
960+
more explicitly descriptive. Use it to better
960961
express intent. The norm in other languages and regular expression
961962
implementations is to use the term *match* to refer to the behavior of
962963
what Python has always called :func:`~re.search`.
@@ -1309,9 +1310,10 @@ Regular expression objects
13091310
:meth:`~Pattern.match`. Use that name when you need to retain compatibility
13101311
with older Python versions.
13111312

1312-
.. versionchanged:: 3.15
1313-
The alternate :meth:`~Pattern.prefixmatch` name of this API was added as
1314-
a more explicitly descriptive name than :meth:`~Pattern.match`. Use it to
1313+
.. deprecated:: 3.15
1314+
:meth:`~Pattern.match` has been :term:`soft deprecated` in favor of
1315+
the alternate :meth:`~Pattern.prefixmatch` name of this API which is
1316+
more explicitly descriptive. Use it to
13151317
better express intent. The norm in other languages and regular expression
13161318
implementations is to use the term *match* to refer to the behavior of
13171319
what Python has always called :meth:`~Pattern.search`.
@@ -1778,16 +1780,22 @@ not familiar with the Python API's divergence from what otherwise become the
17781780
industry norm.
17791781

17801782
Quoting from the Zen Of Python (``python3 -m this``): *"Explicit is better than
1781-
implicit"*. Anyone reading the name :func:`~re.prefixmatch` is likely to
1782-
understand the intended semantics. When reading :func:`~re.match` there remains
1783+
implicit"*. Anyone reading the name :func:`!prefixmatch` is likely to
1784+
understand the intended semantics. When reading :func:`!match` there remains
17831785
a seed of doubt about the intended behavior to anyone not already familiar with
17841786
this old Python gotcha.
17851787

1786-
We **do not** plan to deprecate and remove the older *match* name,
1788+
We **do not** plan to remove the older :func:`!match` name,
17871789
as it has been used in code for over 30 years.
1788-
Code supporting older versions of Python should continue to use *match*.
1790+
It has been :term:`soft deprecated`:
1791+
code supporting older versions of Python should continue to use :func:`!match`,
1792+
while new code should prefer :func:`!prefixmatch`.
17891793

17901794
.. versionadded:: 3.15
1795+
:func:`!prefixmatch`
1796+
1797+
.. deprecated:: 3.15
1798+
:func:`!match` is :term:`soft deprecated`
17911799

17921800
Making a phonebook
17931801
^^^^^^^^^^^^^^^^^^

Doc/whatsnew/3.15.rst

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,9 +922,10 @@ pickle
922922
re
923923
--
924924

925-
* :func:`re.prefixmatch` and a corresponding :meth:`~re.Pattern.prefixmatch`
926-
have been added as alternate more explicit names for the existing
927-
:func:`re.match` and :meth:`~re.Pattern.match` APIs. These are intended
925+
* :func:`re.prefixmatch` and a corresponding :meth:`re.Pattern.prefixmatch`
926+
have been added as alternate, more explicit names for the existing
927+
and now :term:`soft deprecated`
928+
:func:`re.match` and :meth:`re.Pattern.match` APIs. These are intended
928929
to be used to alleviate confusion around what *match* means by following the
929930
Zen of Python's *"Explicit is better than implicit"* mantra. Most other
930931
language regular expression libraries use an API named *match* to mean what
@@ -1624,6 +1625,27 @@ New deprecations
16241625

16251626
(Contributed by Bénédikt Tran in :gh:`134978`.)
16261627

1628+
1629+
* :mod:`re`:
1630+
1631+
* :func:`re.match` and :meth:`re.Pattern.match` are now
1632+
:term:`soft deprecated` in favor of the new :func:`re.prefixmatch` and
1633+
:meth:`re.Pattern.prefixmatch` APIs, which have been added as alternate,
1634+
more explicit names. These are intended to be used to alleviate confusion
1635+
around what *match* means by following the Zen of Python's *"Explicit is
1636+
better than implicit"* mantra. Most other language regular expression
1637+
libraries use an API named *match* to mean what Python has always called
1638+
*search*.
1639+
1640+
We **do not** plan to remove the older :func:`!match` name, as it has been
1641+
used in code for over 30 years. Code supporting older versions of Python
1642+
should continue to use :func:`!match`, while new code should prefer
1643+
:func:`!prefixmatch`. See :ref:`prefixmatch-vs-match`.
1644+
1645+
(Contributed by Gregory P. Smith in :gh:`86519` and
1646+
Hugo van Kemenade in :gh:`148100`.)
1647+
1648+
16271649
* :mod:`struct`:
16281650

16291651
* Calling the ``Struct.__new__()`` without required argument now is
@@ -1696,6 +1718,8 @@ New deprecations
16961718

16971719
.. include:: ../deprecations/pending-removal-in-future.rst
16981720

1721+
.. include:: ../deprecations/soft-deprecations.rst
1722+
16991723

17001724
C API changes
17011725
=============
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:term:`Soft deprecate <soft deprecated>` :func:`re.match` and
2+
:meth:`re.Pattern.match` in favour of :func:`re.prefixmatch` and
3+
:meth:`re.Pattern.prefixmatch`. Patch by Hugo van Kemenade.

0 commit comments

Comments
 (0)