-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-143984: Replace optparse with argparse in Lib/test/test_decimal.py #143983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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') | ||||||||||||||||||||||||||||||
|
Comment on lines
+6033
to
+6034
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The short option usually goes before the long, and this matches
Suggested change
|
||||||||||||||||||||||||||||||
| parser.add_argument('tests', nargs='*', help='specific tests to run') | ||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| 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) | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||
| Replace the usage of the deprecated optparse module with argparse in Lib/test/test_decimal.py. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in the issue, optparse is no longer deprecated.
Suggested change
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let argparse generate the usage, and it'll use colour for the different parts. And put the positional arg first, to match help output: