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
Moving a2x from optparse to argparse #34
Conversation
Help output:
|
Looks ok to me, @MasterOdin ? |
LGTM |
While trying to package asciidoc 9.x for my distro, I discovered this change resulted in a regression. Previously working software which depends on asciidoc to build documentation, stopped working with the following message:
Note the option
This is caused by python bug https://bugs.python.org/issue9334 argparse is NOT a drop-in replacement for optparse, and quite frankly on a personal level I'm now disappointed in argparse and no longer wish to use it for things. |
Try |
This is a demonstration of the bug, not an assertion that I only have the bug in one place. I don't anticipate having fun testing around a hundred packages which have build-depends on asciidoc to check which ones might trigger a bug in a2x/argparse, then adding workarounds there, before I can package asciidoc. Though at least in the case of this one package, I will now have a) ugly code doing even more nested array joining and string Furthermore this is broken argument parsing behavior, but apparently no python developers care sufficiently about having correct behavior to fix this over the course of a decade, leading me to the inevitable conclusion that argparse itself will never be fixed. This is a general issue in that people using asciidoc might not expect the equals sign to be needed there, as it never was before and it breaks from common option parsing conventions. They will get strange errors from argparse but think those errors come from a2x. |
This shows the Note that I am carefully not buying into the argument about which is correct, argparse or optparse, so I am not using terms like 'bug' or 'broken' for either behaviour :) |
Note I would also need to protect:
because the only reason that isn't an argparse error too, is because currently a2x doesn't accept a |
I didn't notice that, but on the other hand the --help output shows it without the "=". Because argparse controls that. Anyway it's generally expected UX for tools in general that this should not make a difference and both forms work. And... both forms do work, superficially (until argparse misinterprets them). Nowhere does it say "you really need the equals sign, even though you might think it works without it".
FWIW, optparse is "documentation-only" deprecation and I believe it's not intended to ever remove it. |
Who am I kidding, I love a good syntax lawyer argument, so ... :)
Posix does not address long options so they are non-standard, so we need to turn to the glibc extension that AFAICT was the first to allow long arguments, so having priority for defining "correct" behaviour of long options. Glibc specified a requirement for the value for a long argument to be attached by So AFAICT it was Python optparse() that added the non-standard behaviour for long options on its own, possibly accidentally because its how POSIX short options are defined to operate with arguments, and the same code was also used for long arguments without anybody noticing the implications. But it opens up the ambiguities that are happening here, and that the Glibc specification avoids. Since optparse() has been around for a long time it might therefore be common for Python applications to accept such argument lists , but I would disagree that it is "generally expected UX behaviour" with non-python applications, and the non-standard behaviour has ambiguity that leads to these sorts of arguments [pun intended]. Although argparse is more standard in that it doesn't accept disconnected argument values starting with And argparse() help is also broken, as you pointed out it does not show the Agree that I wouldn't expect optparse to be removed before Python 4, but the change will occur at some time, and in between optparse is unlikely to get much love. So all-in-all, for me, the whole Python argument parsing ecosystem is pretty much broken and non-standard and encourages users to use ambiguous commands without the So finally getting back to Asciidoc, I would take the view that the Asciidoc documentation (RTFineM remember :) always showed the correct standard (for non-python apps) usage, and the fact that the non-standard usage happened to work was an artefact (or even a bug) not a deliberate feature. As such it can cease working at any time. It is unfortunate that the incorrect usage has propagated far and wide, but that is going to have to be fixed at some point. I understand that there is effort in changing lots of uses and that takes time, so I might have suggested that the change be reverted and a deprecation period given to allow time for the erroneous commands in scripts to be fixed. But since it seems nobody reads the asciidoc documentation anyway, I'm not sure how the deprecation would be communicated, especially for existing scripts buried inside other applications build systems, so nobody will notice such a deprecation and all it will do is delay the inevitable. [end lawyering, I rest my case m'lud] |
Given the intention to make the 9.0 release a painless upgrade from 8.6.10, I agree on reverting this PR. I'll do this later on today in a 9.0.2 release as I agree this is a "bug" in the context of the above statement. The rest of the conversation on usage syntax and such can be used as context for whether we do actually want to move to argparse from optparse until we're actually forced to so as to retain this behavior, and any such change would be for 10.0, to be included with other BC breaking changes. |
Ping? |
This reverts commit e3fd0a7.
Sorry about that @eli-schwartz, it ended up totally slipping my mind. I've now properly cut 9.0.2. |
Tested the following elements, no issue after the change:
Note the change from
eval(str(...))
to the use of the builtinvars(...)
that provides the same result but safer.Along with #33 it closes: #4