Skip to content

Commit 5fee791

Browse files
committed
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.
1 parent 7e28ae5 commit 5fee791

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

Lib/test/test_decimal.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6028,15 +6028,16 @@ def test(arith=None, verbose=None, todo_tests=None, debug=None):
60286028

60296029

60306030
if __name__ == '__main__':
6031-
import optparse
6032-
p = optparse.OptionParser("test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]")
6033-
p.add_option('--debug', '-d', action='store_true', help='shows the test number and context before each test')
6034-
p.add_option('--skip', '-s', action='store_true', help='skip over 90% of the arithmetic tests')
6035-
(opt, args) = p.parse_args()
6036-
6037-
if opt.skip:
6031+
import argparse
6032+
parser = argparse.ArgumentParser(usage="test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]")
6033+
parser.add_argument('--debug', '-d', action='store_true', help='shows the test number and context before each test')
6034+
parser.add_argument('--skip', '-s', action='store_true', help='skip over 90%% of the arithmetic tests')
6035+
parser.add_argument('tests', nargs='*', help='specific tests to run')
6036+
args = parser.parse_args()
6037+
6038+
if args.skip:
60386039
test(arith=False, verbose=True)
6039-
elif args:
6040-
test(arith=True, verbose=True, todo_tests=args, debug=opt.debug)
6040+
elif args.tests:
6041+
test(arith=True, verbose=True, todo_tests=args.tests, debug=args.debug)
60416042
else:
60426043
test(arith=True, verbose=True)

0 commit comments

Comments
 (0)