This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: argparse docs: default for prog= in ArgumentParser() should be basename of argv[0], not argv[0], to match behaviour
Type: behavior Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, lf-, miss-islington, paul.j3, rhettinger
Priority: normal Keywords: patch

Created on 2022-01-02 19:50 by lf-, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py lf-, 2022-01-02 19:50 Test program from above
Pull Requests
URL Status Linked Edit
PR 30298 merged lf-, 2022-01-02 19:50
PR 30339 merged miss-islington, 2022-01-02 20:19
Messages (2)
msg409515 - (view) Author: Jade Lovelace (lf-) Date: 2022-01-02 19:50
Currently the documentation for argparse.ArgumentParser states that the default value of the prog[ram] argument is argv[0], however, this does not match the actual behaviour of the constructor. In reality, the constructor uses the basename of argv[0], as can be seen in the code here: https://github.com/python/cpython/blob/e800dd1793dafbc4114da744f605731ff6630623/Lib/argparse.py#L1733-L1735

Here is a demo:

/tmp » cat test.py
import argparse

ap = argparse.ArgumentParser()
print(ap.prog)
ap.print_usage()
/tmp » python test.py
test.py
usage: test.py [-h]
/tmp » python ./test.py
test.py
usage: test.py [-h]
/tmp » mkdir test
/tmp » cd test
/tmp/test » python ../test.py
test.py
usage: test.py [-h]
msg409518 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2022-01-02 20:19
Thank you for the PR.
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90386
2022-02-02 16:56:39paul.j3setnosy: + paul.j3
2022-01-02 20:19:59rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg409518

resolution: fixed
stage: patch review -> resolved
2022-01-02 20:19:23miss-islingtonsetkeywords: + patch
nosy: + miss-islington
pull_requests: + pull_request28551
2022-01-02 20:09:30eric.araujosetnosy: + docs@python
versions: - Python 3.6, Python 3.7, Python 3.8
assignee: docs@python
components: + Documentation
type: enhancement -> behavior
stage: patch review
2022-01-02 19:50:38lf-create