-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
gh-66436: Improved prog default value for argparse.ArgumentParser #124799
Conversation
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
5ba9a91
to
1977630
Compare
Lib/argparse.py
Outdated
if (modspec.name == '__main__' and not modspec.parent and modspec.has_location | ||
and _os.path.dirname(modspec.origin) == _os.path.join(_os.getcwd(), arg0)): |
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.
Actually, it seems that this condition can be simplified to simply modspec.name == '__main__'
. What are your thoughts @ncoghlan?
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.
Actually, additionally checks were just an obstacle, because of differences in normalization between Unix and Windows. So I removed them.
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.
LGTM! Assorted minor comments inline, either tweaking docs wording, or else making the code handle obscure edge cases more gracefully.
Misc/NEWS.d/next/Library/2024-09-30-19-59-28.gh-issue-66436.4gYN_n.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Alyssa Coghlan <[email protected]>
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.
Thank you for your suggestions @ncoghlan. I applied them all.
It can now have one of three forms:
📚 Documentation preview 📚: https://cpython-previews--124799.org.readthedocs.build/