Skip to content

gh-66436: Improved prog default value for argparse.ArgumentParser #124799

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

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Sep 30, 2024

It can now have one of three forms:

  • basename(argv0) -- for simple scripts
  • python arv0 -- for directories, ZIP files, etc
  • python -m module -- for imported modules

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

It can now have one of three forms:

* basename(argv0) -- for simple scripts
* python arv0 -- for directories, ZIP files, etc
* python -m module -- for imported modules
@serhiy-storchaka serhiy-storchaka force-pushed the argparse-default-prog-name branch from 5ba9a91 to 1977630 Compare September 30, 2024 19:52
Lib/argparse.py Outdated
Comment on lines 1708 to 1709
if (modspec.name == '__main__' and not modspec.parent and modspec.has_location
and _os.path.dirname(modspec.origin) == _os.path.join(_os.getcwd(), arg0)):
Copy link
Member Author

@serhiy-storchaka serhiy-storchaka Sep 30, 2024

Choose a reason for hiding this comment

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

Actually, it seems that this condition can be simplified to simply modspec.name == '__main__'. What are your thoughts @ncoghlan?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, additionally checks were just an obstacle, because of differences in normalization between Unix and Windows. So I removed them.

Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

LGTM! Assorted minor comments inline, either tweaking docs wording, or else making the code handle obscure edge cases more gracefully.

Copy link
Member Author

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Thank you for your suggestions @ncoghlan. I applied them all.

@serhiy-storchaka serhiy-storchaka merged commit 04bfea2 into python:main Oct 1, 2024
34 checks passed
@serhiy-storchaka serhiy-storchaka deleted the argparse-default-prog-name branch October 1, 2024 19:51
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.

2 participants