Implement improved optional optarg parsing for short option.#25
Implement improved optional optarg parsing for short option.#25dapimentel wants to merge 2 commits intoskeeto:masterfrom
Conversation
|
Thank you for taking the time and effort to prepare these patches (here and #26), @dapimentel. While I appreciate that the changes are opt-in at compile time, the original behavior is very much deliberate and intended. A few popular argument parsers try to second-guess users' unambiguous intentions, but such behavior is surprising and hazardous. The designers of these parsers are confused. See this discussion on Python argparse. On the plus side, your changes aren't nearly as hazardous as argparse, clap, etc. because the guessing behavior strictly applies to optional option arguments, not to every argument-accepting option. The hazard comes from passing arguments programmatically, e.g. in a script. For example (long case): The argument is quoted, so it seems like it ought to be safe to use with an untrusted The hazard is that the first usually works, and so you don't know you've made a mistake. The current (and still the default with your patch) behavior of Optparse will not produce the desired results in the first case regardless of the value of In case it seems far fetched, here's an example I found within about a minute of looking (not trying to pick on this article, these mistakes are common and widespread): https://til.simonwillison.net/python/uv-tests
It annoys me when software second-guesses my unambiguous inputs, and I don't want to encourage this behavior in my library. I'm still glad you've opened this PR because it's highlighted this important subtly. |
|
Also worth noting that if The GNU definition isn't ridiculous, it's a simple case of (wisely) choosing to avoid ambiguous grammar. |
Given the following simple patch to long.c, the undesirable feature of parsing optional arguments is demonstrated:
First use case fails to reset the delay value.
Second use case resets the delay value.
Both use cases should behave the same as the second, regardless of the ridculous definition for the GNU extension:
This preferred behavior is as simple as activating the included patch.