[New-bugs-announce] [issue46228] argparse docs: default for prog= in ArgumentParser() should be basename of argv[0], not argv[0], to match behaviour

Jade Lovelace report at bugs.python.org
Sun Jan 2 14:50:38 EST 2022


New submission from Jade Lovelace <software at lfcode.ca>:

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]

----------
components: Library (Lib)
files: test.py
messages: 409515
nosy: lf-
priority: normal
pull_requests: 28549
severity: normal
status: open
title: argparse docs: default for prog= in ArgumentParser() should be basename of argv[0], not argv[0], to match behaviour
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file50536/test.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46228>
_______________________________________


More information about the New-bugs-announce mailing list