From 541e56656e9ac3d6572e32049eadc6af95b6fbd9 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Thu, 26 Feb 2026 12:46:29 -0700 Subject: [PATCH 1/2] gh-145269: simplify bisect.bisect doc example --- Doc/library/bisect.rst | 6 +++--- Lib/test/test_bisect.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/bisect.rst b/Doc/library/bisect.rst index 7f75e85a7eb641..a1fc64c57908d1 100644 --- a/Doc/library/bisect.rst +++ b/Doc/library/bisect.rst @@ -200,9 +200,9 @@ example uses :py:func:`~bisect.bisect` to look up a letter grade for an exam sco based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is a 'B', and so on:: - >>> def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'): - ... i = bisect(breakpoints, score) - ... return grades[i] + >>> def grade(score) + ... i = bisect([60, 70, 80, 90, score) + ... return "FDCBA"[i] ... >>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]] ['F', 'A', 'C', 'C', 'B', 'A', 'A'] diff --git a/Lib/test/test_bisect.py b/Lib/test/test_bisect.py index 97204d4cad3871..a7e1f533ff2adc 100644 --- a/Lib/test/test_bisect.py +++ b/Lib/test/test_bisect.py @@ -391,9 +391,9 @@ class TestErrorHandlingC(TestErrorHandling, unittest.TestCase): class TestDocExample: def test_grades(self): - def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'): - i = self.module.bisect(breakpoints, score) - return grades[i] + def grade(score): + i = self.module.bisect([60, 70, 80, 90], score) + return "FDCBA"[i] result = [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]] self.assertEqual(result, ['F', 'A', 'C', 'C', 'B', 'A', 'A']) From 09c79652866c40587d4d75332b97648eff6ba4d4 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Thu, 26 Feb 2026 13:19:54 -0700 Subject: [PATCH 2/2] Update Doc/library/bisect.rst Co-authored-by: Pieter Eendebak --- Doc/library/bisect.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/bisect.rst b/Doc/library/bisect.rst index a1fc64c57908d1..2c29a5ec992737 100644 --- a/Doc/library/bisect.rst +++ b/Doc/library/bisect.rst @@ -201,7 +201,7 @@ based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is a 'B', and so on:: >>> def grade(score) - ... i = bisect([60, 70, 80, 90, score) + ... i = bisect([60, 70, 80, 90], score) ... return "FDCBA"[i] ... >>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]