Documentation
I was checking if the current version of argparse supports arguments which are negative floating-point number in scientific notation, such as -2.5e-6, as I remember this used to an issue. To my delight, thanks to #124823, doing something like --num -2.5e-6 and other kinds of negative numbers is good now! (from Python 3.14)
I guess the relevant documentation may benefit from having this change of behaviour documented, as there is a genuine difference of running the snippet below with different versions of Python:
import argparse
p = argparse.ArgumentParser()
p.add_argument('--num')
# error: py311, py312, py313
# ok: py314
ns = p.parse_args(['--num', '-1.2e-3j'])
ns = p.parse_args(['--num', '-2.5e-6'])
ns = p.parse_args(['--num', '-1_234.5'])
ns = p.parse_args(['--num', '-.12'])
I have tested 3.11 to 3.13 and all the above cases failed, while 3.14 (and the current main) is fine. This impacts how the users design the parser in different versions of Python, so this change of behaviour should probably be documented.
On a related note, the case ns = p.parse_args(['--num', '-3,5-10']) from #138950 is fine from 3.14 without the 'nargs trick', could we consider #138950 as resolved?
Linked PRs
Documentation
I was checking if the current version of
argparsesupports arguments which are negative floating-point number in scientific notation, such as-2.5e-6, as I remember this used to an issue. To my delight, thanks to #124823, doing something like--num -2.5e-6and other kinds of negative numbers is good now! (from Python 3.14)I guess the relevant documentation may benefit from having this change of behaviour documented, as there is a genuine difference of running the snippet below with different versions of Python:
I have tested 3.11 to 3.13 and all the above cases failed, while 3.14 (and the current main) is fine. This impacts how the users design the parser in different versions of Python, so this change of behaviour should probably be documented.
On a related note, the case
ns = p.parse_args(['--num', '-3,5-10'])from #138950 is fine from 3.14 without the 'nargstrick', could we consider #138950 as resolved?Linked PRs