FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-68583: webbrowser: replace `getopt` with `argparse`, add long options by hugovk · Pull Request #117047 · python/cpython · GitHub

/ cpython Public

gh-68583: webbrowser: replace getopt with argparse, add long options - #117047

Merged
hugovk merged 17 commits into
python:mainfrom
hugovk:webbrowser-argparse
Apr 13, 2024
Merged

gh-68583: webbrowser: replace getopt with argparse, add long options#117047
hugovk merged 17 commits into
python:mainfrom
hugovk:webbrowser-argparse

Conversation

hugovk commented Mar 19, 2024
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

Replace getopt with argparse in webbrowser's CLI.

Also add long options for -n and -t: --new-window and --new-tab.

Add tests for the CLI (inspired by https://pythontest.com/testing-argparse-apps/), and for an error case of new().

Before

./python.exe -m webbrowser --help
Usage: /Users/hugo/github/python/cpython/main/Lib/webbrowser.py [-n | -t | -h] url
    -n: open new window
    -t: open new tab
    -h, --help: show help

After

./python.exe -m webbrowser --help
usage: webbrowser.py [-h] [-n | -t] url

Open URL in a web browser.

positional arguments:
  url               URL to open

options:
  -h, --help        show this help message and exit
  -n, --new-window  open new window
  -t, --new-tab     open new tab

Plus some cleanup:

  • Fix whitespace
  • Fix/use f-strings
  • Remove redundant parentheses
  • Use triple backticks for docstrings
  • Use new-style class

📚 Documentation preview 📚: https://cpython-previews--117047.org.readthedocs.build/

Comment thread Lib/webbrowser.py Outdated

terryjreedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I did not look at the new CliTest class. I have not use argparse but have read doc and examples and it looks good, and much nicer than existing. One suggestion.

Comment thread Lib/webbrowser.py
Comment thread Lib/webbrowser.py Outdated

bedevere-app Bot commented Apr 10, 2024

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Comment thread Lib/webbrowser.py

url = args[0]
open(url, new_win)
def parse_args(arg_list: list[str] | None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What's our current policy on stdlib type hints?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

python/devguide#1304 says in general don't add, but there are some specific exceptions, but that the policy is undocumented. I think these might be okay because they're "simple" and internal, but I'm also happy to remove if you'd prefer?

"https://example.com -n -t",
"https://example.com --new-window --new-tab",
"https://example.com -n --new-tab",
"https://example.com --new-window -t",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

argparse allows argument shortening and handles ambiguous shortenings as one might hope, but it might be nice to confirm that --new fails properly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nice, I didn't know about that feature :) I've added a test case.

hugovk merged commit 56ed979 into python:main Apr 13, 2024
hugovk deleted the webbrowser-argparse branch April 13, 2024 14:56
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL