From a590a972903ac3a3f12df7f4fabab25654774271 Mon Sep 17 00:00:00 2001 From: Dennis Sweeney Date: Tue, 21 May 2019 21:19:01 -0400 Subject: [PATCH 1/4] Warning that SequenceMatcher.ratio() is not commutative --- Doc/library/difflib.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst index f044cb2d6e0a86..2101c534ed0192 100644 --- a/Doc/library/difflib.rst +++ b/Doc/library/difflib.rst @@ -543,6 +543,16 @@ The :class:`SequenceMatcher` class has this constructor: to try :meth:`quick_ratio` or :meth:`real_quick_ratio` first to get an upper bound. + .. note:: + + Caution: The result of a :meth:`ratio` call is *NOT* symmetric with + respect to the order of the arguments. For instance:: + + >>> SequenceMatcher(None, 'brady', 'byrd').ratio() + 0.6666666666666666 + >>> SequenceMatcher(None, 'byrd', 'brady').ratio() + 0.4444444444444444 + .. method:: quick_ratio() From a6ab363ad0ff7af723f3ed4798e9f918e790d7bf Mon Sep 17 00:00:00 2001 From: Dennis Sweeney Date: Tue, 21 May 2019 23:11:40 -0400 Subject: [PATCH 2/4] Rephrased SequenceMatcher warning and changed example --- Doc/library/difflib.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst index 2101c534ed0192..1b0cef936dd3a2 100644 --- a/Doc/library/difflib.rst +++ b/Doc/library/difflib.rst @@ -545,13 +545,13 @@ The :class:`SequenceMatcher` class has this constructor: .. note:: - Caution: The result of a :meth:`ratio` call is *NOT* symmetric with - respect to the order of the arguments. For instance:: + Caution: The result of a :meth:`ratio` call may depend on the order of + the arguments. For instance:: - >>> SequenceMatcher(None, 'brady', 'byrd').ratio() - 0.6666666666666666 - >>> SequenceMatcher(None, 'byrd', 'brady').ratio() - 0.4444444444444444 + >>> SequenceMatcher(None, 'tide', 'diet').ratio() + 0.25 + >>> SequenceMatcher(None, 'diet', 'tide').ratio() + 0.5 .. method:: quick_ratio() From 8f2aab82ba92c70eb438a3d364c62f1911f6e788 Mon Sep 17 00:00:00 2001 From: Dennis Sweeney Date: Wed, 22 May 2019 00:22:14 -0400 Subject: [PATCH 3/4] removed trailing whitespace --- Doc/library/difflib.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst index 1b0cef936dd3a2..e245ab81cfb949 100644 --- a/Doc/library/difflib.rst +++ b/Doc/library/difflib.rst @@ -547,7 +547,7 @@ The :class:`SequenceMatcher` class has this constructor: Caution: The result of a :meth:`ratio` call may depend on the order of the arguments. For instance:: - + >>> SequenceMatcher(None, 'tide', 'diet').ratio() 0.25 >>> SequenceMatcher(None, 'diet', 'tide').ratio() From 0683a5f478c42528b06b33a9d1c074b18801d668 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Wed, 22 May 2019 04:30:08 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Documentation/2019-05-22-04-30-07.bpo-37004.BRgxrt.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Documentation/2019-05-22-04-30-07.bpo-37004.BRgxrt.rst diff --git a/Misc/NEWS.d/next/Documentation/2019-05-22-04-30-07.bpo-37004.BRgxrt.rst b/Misc/NEWS.d/next/Documentation/2019-05-22-04-30-07.bpo-37004.BRgxrt.rst new file mode 100644 index 00000000000000..dfc8b7ed74cae0 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2019-05-22-04-30-07.bpo-37004.BRgxrt.rst @@ -0,0 +1 @@ +In the documentation for difflib, a note was added explicitly warning that the results of SequenceMatcher's ratio method may depend on the order of the input strings. \ No newline at end of file