Skip to content

gh-118131: Command-line interface for the random module #118132

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

Merged
merged 4 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename parse_args to _parse_args
  • Loading branch information
hugovk committed May 2, 2024
commit 15dec310aebbd4907e8dda1838d26938637f6f77
4 changes: 2 additions & 2 deletions Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ def _test(N=10_000):
# -------------- command-line interface ----------------


def parse_args(arg_list: list[str] | None):
def _parse_args(arg_list: list[str] | None):
import argparse
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter)
Expand Down Expand Up @@ -1028,7 +1028,7 @@ def parse_args(arg_list: list[str] | None):


def main(arg_list: list[str] | None = None) -> int | str:
args, help_text = parse_args(arg_list)
args, help_text = _parse_args(arg_list)

# Explicit arguments
if args.choice:
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,27 +1400,27 @@ def test_after_fork(self):

class CommandLineTest(unittest.TestCase):
def test_parse_args(self):
args, help_text = random.parse_args(shlex.split("--choice a b c"))
args, help_text = random._parse_args(shlex.split("--choice a b c"))
self.assertEqual(args.choice, ["a", "b", "c"])
self.assertTrue(help_text.startswith("usage: "))

args, help_text = random.parse_args(shlex.split("--integer 5"))
args, help_text = random._parse_args(shlex.split("--integer 5"))
self.assertEqual(args.integer, 5)
self.assertTrue(help_text.startswith("usage: "))

args, help_text = random.parse_args(shlex.split("--float 2.5"))
args, help_text = random._parse_args(shlex.split("--float 2.5"))
self.assertEqual(args.float, 2.5)
self.assertTrue(help_text.startswith("usage: "))

args, help_text = random.parse_args(shlex.split("a b c"))
args, help_text = random._parse_args(shlex.split("a b c"))
self.assertEqual(args.input, ["a", "b", "c"])
self.assertTrue(help_text.startswith("usage: "))

args, help_text = random.parse_args(shlex.split("5"))
args, help_text = random._parse_args(shlex.split("5"))
self.assertEqual(args.input, ["5"])
self.assertTrue(help_text.startswith("usage: "))

args, help_text = random.parse_args(shlex.split("2.5"))
args, help_text = random._parse_args(shlex.split("2.5"))
self.assertEqual(args.input, ["2.5"])
self.assertTrue(help_text.startswith("usage: "))

Expand Down