-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
allow_abbrev=False does not work for single-dash long options #104860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
3.6 is unsupported and 3.8 is only receiving security fixes, so neither version is going to change here. However, 3.12 behaves like 3.8 ( |
I think --output-name is long option, while -on is a short option (1 vs 2 hyphens). And I'm confused how two letter short option is intended to be interpreted. It's not being treated as 2 short options of -o + -n because ['-n', 'dir'] does get ignored. While it feels like weird behavior, the bigger question to me is there any documentation for how one hyphen multiple character flag is supposed to behave? Is -on meant to be one 2 letter option or 2 one character options? If it's a 2 letter option what's difference between -on vs --on? |
I think so. The prefix matching code should be reverted to 3.6 version if we are following what the description is telling us. |
The code in. The same method ( Current behaviour looks intentional ("-o dir" uses the short option, not an abbrev of the long option), but I'm far from an expert on argparse. Regardless of this, the current behaviour is present in 3.8 - 3.12 and changing this can break other users. |
Originally abbreviations were allowed. Then we added this parameter to turn that off. But that proved to be buggy, since it broke the chained short option case. That was patched, probably between 3.6 and 3.8.. Feel free to search for the relevant issues and patches. So '-o' is allowed as an abbreviation of '-on', hence the 3.8 behavior. While '-o' is the "ideal" short option, the distinction between long and short is handled piecemeal. So '-on' qualifies as short (in the abbreviation context), even though it wouldn't be handled as such in the chaining context. I suppose we could add a test in Paul |
It seems that this is intended behaviour due to the changes mentioned above. A |
No. This change is unexpected and problematic. It's just that nobody is maintaining this library, and no one is willing to fix this bug for compatibility reasons. |
I read that from the below, sorry for the confusion.
|
If the behavior is hard to change, at least we can document the current behavior. The current explanation is ambiguous. Improving the documentation is achievable here. |
What wording would clarify things for you? Developers tend to overlook
ambiguities and unfamiliar interpretations.
The `allow_abbrev` docs clearly says it applies to `long options`, but the distinction between long and short is not clearly defined elsewhere in the docs. I scaned it a few days ago, and my memory is that:
In the section about setting the `dest`, '--long' is clearly given priority, with '-long' being a fall back choice.
In another place '--long=va' and '-long=val' are treated the same. But for chaining shorts, a single character short is clearly assumed.
Toward then end, the `Argument abbreviations (prefix matching)` section has examples with strings like '-badger' and '-bacon'. I haven't thought through that carefully, or tried to test them, but that may be buggy, and misleading.
This documentation ambiguity relects, in part, the decentralized way in which the code itself handles single/double dash, and single/multicharacter options.
So more systematically we have
true long - anything begining with '--' (2 prefix)
true short - one dash, one character
pseudo long - one dash, more than one character
equals - anyting with '='
|
This is not intentional behavior, but a bug that was introduced in process of fixing flag grouping with allow_abbrev=False, presumably in dffca9e (bpo-26967).
|
…ythonGH-124340) (cherry picked from commit 49e105f) Co-authored-by: Serhiy Storchaka <[email protected]>
…ythonGH-124340) (cherry picked from commit 49e105f) Co-authored-by: Serhiy Storchaka <[email protected]>
…GH-124340) (GH-124750) (cherry picked from commit 49e105f) Co-authored-by: Serhiy Storchaka <[email protected]>
…GH-124340) (GH-124749) (cherry picked from commit 49e105f) Co-authored-by: Serhiy Storchaka <[email protected]>
Bug report
The following codes get different results between python3.6.9 and python3.8.10
python3.6.9
python3.8.10
Debug
I have tried to debug the codes and get some clues.
I have set the
allow_abbrev=False
to disable prefix match, but it works in python3.6.9 and fails in python3.8.10.When I div into
argparse.py
and find that it considers the allow_abbrev in python3.6.9 but not in python3.8.10 as follow:in python3.6.9 argparse.py
in python3.8.10 argparse.py
Linked PRs
The text was updated successfully, but these errors were encountered: