New submission from Jade Lovelace <softw...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue46228>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to