From 5fee79161a9c1603d1c42d21bada1ceb66927ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tonghuaroot=20=28=E7=AB=A5=E8=AF=9D=29?= Date: Sun, 18 Jan 2026 13:07:36 +0800 Subject: [PATCH 1/5] gh-143984: Replace optparse with argparse in Lib/test/test_decimal.py The optparse module is deprecated since Python 3.2. This change migrates Lib/test/test_decimal.py to use the argparse module for command line argument parsing. This involves: - Importing argparse instead of optparse. - Using ArgumentParser instead of OptionParser. - Updating argument definitions (add_argument). - Escaping '%' characters in help strings. - Updating execution logic to use the argparse Namespace object. --- Lib/test/test_decimal.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index b520b062ebc685..702558c3eb892c 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -6028,15 +6028,16 @@ def test(arith=None, verbose=None, todo_tests=None, debug=None): if __name__ == '__main__': - import optparse - p = optparse.OptionParser("test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]") - p.add_option('--debug', '-d', action='store_true', help='shows the test number and context before each test') - p.add_option('--skip', '-s', action='store_true', help='skip over 90% of the arithmetic tests') - (opt, args) = p.parse_args() - - if opt.skip: + import argparse + parser = argparse.ArgumentParser(usage="test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]") + parser.add_argument('--debug', '-d', action='store_true', help='shows the test number and context before each test') + parser.add_argument('--skip', '-s', action='store_true', help='skip over 90%% of the arithmetic tests') + parser.add_argument('tests', nargs='*', help='specific tests to run') + args = parser.parse_args() + + if args.skip: test(arith=False, verbose=True) - elif args: - test(arith=True, verbose=True, todo_tests=args, debug=opt.debug) + elif args.tests: + test(arith=True, verbose=True, todo_tests=args.tests, debug=args.debug) else: test(arith=True, verbose=True) From 359bcab7a22829ddb74ec7e915c213b4a63f53f3 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 18 Jan 2026 05:42:42 +0000 Subject: [PATCH 2/5] =?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/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst diff --git a/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst b/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst new file mode 100644 index 00000000000000..3d441c380e8d8b --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst @@ -0,0 +1 @@ +Replace the usage of the deprecated optparse module with argparse in Lib/test/test_decimal.py. From 53d8e1fd8feaca4be8abc8a596a7b9f4229a1d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tonghuaroot=20=28=E7=AB=A5=E8=AF=9D=29?= Date: Sun, 18 Jan 2026 21:55:22 +0800 Subject: [PATCH 3/5] Update Lib/test/test_decimal.py Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Lib/test/test_decimal.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 702558c3eb892c..33b64f8d4e9bed 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -6029,10 +6029,22 @@ def test(arith=None, verbose=None, todo_tests=None, debug=None): if __name__ == '__main__': import argparse - parser = argparse.ArgumentParser(usage="test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]") - parser.add_argument('--debug', '-d', action='store_true', help='shows the test number and context before each test') - parser.add_argument('--skip', '-s', action='store_true', help='skip over 90%% of the arithmetic tests') - parser.add_argument('tests', nargs='*', help='specific tests to run') + + parser = argparse.ArgumentParser() + group = parser.add_mutually_exclusive_group() + group.add_argument("tests", nargs="*", default=[], help="specific tests to run") + group.add_argument( + "-s", + "--skip", + action="store_true", + help="skip over 90%% of the arithmetic tests", + ) + parser.add_argument( + "-d", + "--debug", + action="store_true", + help="shows the test number and context before each test", + ) args = parser.parse_args() if args.skip: From aa82dbc4342c0df117103bd55533e7e0387e23b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tonghuaroot=20=28=E7=AB=A5=E8=AF=9D=29?= Date: Sun, 18 Jan 2026 21:55:31 +0800 Subject: [PATCH 4/5] Update Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- .../next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst b/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst index 3d441c380e8d8b..6a72e439ac1fec 100644 --- a/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst +++ b/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst @@ -1 +1 @@ -Replace the usage of the deprecated optparse module with argparse in Lib/test/test_decimal.py. +Replace :mod:`optparse` with :mod:`argparse` in ``Lib/test/test_decimal.py``. From d0f0d81c6d65b859a9c45734b4eac730188d0d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tonghuaroot=20=28=E7=AB=A5=E8=AF=9D=29?= Date: Mon, 19 Jan 2026 00:35:13 +0800 Subject: [PATCH 5/5] Update NEWS entry: emphasize improved help output --- .../next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst b/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst index 6a72e439ac1fec..8dfc6fa93503a1 100644 --- a/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst +++ b/Misc/NEWS.d/next/Tests/2026-01-18-05-42-41.gh-issue-143984.n1imyc.rst @@ -1 +1 @@ -Replace :mod:`optparse` with :mod:`argparse` in ``Lib/test/test_decimal.py``. +Improve the help output of ``Lib/test/test_decimal.py`` by switching to :mod:`argparse`, adding colorized help and better grouping.