You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find this surprising, and a user of one of my tools was surprised that it was accepting two directories but silently only acting on the last one. He was expecting it to act on both.
I note that argparse too silently discards repeated options:
This behaviour comes from argparse._StoreAction, where it doesn't check that a value has previously been assigned to the namespace. But one could overwrite it by defining a new Action that does check.
A colleague noted that this overriding behaviour exists in other Unix tools and perhaps for good reason:
$ alias ls="ls --color=always"
$ ls --color=never
... prints without color
But that's inconsistent with the view that we're just calling a Python function. In Python, repeating a keyword argument throws a TypeError or a SyntaxError:
The text was updated successfully, but these errors were encountered:
lordmauve
changed the title
Detect duplicate (dropped) options
Reject duplicate options for a single parameter rather than silently dropping one
Apr 7, 2022
I think this would be better served by #95? The default behavior of later args overwriting earlier ones is very standard for command line tools and I would be loath to even provide a knob to make that error out (well, unless you can convince the argparse maintainers that this would be good to have -- if this indeed goes into e.g. Py3.12 I could backport whatever changes they make to argparse), especially as that doesn't really solve your original issue whereas #95 does.
OTOH someone actually needs to write the support for Annotated suggested in #95 :-)
When given the same argument multiple times, defopt silently discards all but the last:
I find this surprising, and a user of one of my tools was surprised that it was accepting two directories but silently only acting on the last one. He was expecting it to act on both.
I note that
argparse
too silently discards repeated options:This behaviour comes from argparse._StoreAction, where it doesn't check that a value has previously been assigned to the namespace. But one could overwrite it by defining a new Action that does check.
A colleague noted that this overriding behaviour exists in other Unix tools and perhaps for good reason:
But that's inconsistent with the view that we're just calling a Python function. In Python, repeating a keyword argument throws a TypeError or a SyntaxError:
The text was updated successfully, but these errors were encountered: