Whole file
jazzband/docopt-ng
The author described this change as “Fix bug when user error was shown in case of developer error.”. It counts as a record because the check below fails on the code as it stood at 1d9152082 and passes on e5e4a8983, with nothing else changed between the two runs.
Projectjazzband/docopt-ng
Fix saved2012-06-12
Sharing licenceMIT · LICENSE-MIT
Change size+6 −6
What the code was meant to do, written into the code itself as a save note
Fix bug when user error was shown in case of developer error.
The change
| 424 | 424 | if help and any((o.name in ('-h', '--help')) and o.value for o in options): | |
| 425 | 425 | print(doc.strip()) | |
| 426 | 426 | exit() | |
| 427 | - | if version and any(o.long == '--version' and o.value for o in options): | |
| 427 | + | if version and any(o.name == '--version' and o.value for o in options): | |
| 428 | 428 | print(version) | |
| 429 | 429 | exit() | |
| 430 | 430 | ||
| ⋯ | |||
| 437 | 437 | def docopt(doc, argv=sys.argv[1:], help=True, version=None): | |
| 438 | 438 | DocoptExit.usage = docopt.usage = usage = printable_usage(doc) | |
| 439 | 439 | pot_options = parse_doc_options(doc) | |
| 440 | - | argv = parse_args(argv, options=pot_options) | |
| 441 | - | options = [o for o in argv if type(o) is Option] | |
| 442 | - | extras(help, version, options, doc) | |
| 443 | 440 | formal_pattern = parse_pattern(formal_usage(usage), options=pot_options) | |
| 441 | + | argv = parse_args(argv, options=pot_options) | |
| 442 | + | extras(help, version, argv, doc) | |
| 444 | 443 | matched, left, arguments = formal_pattern.fix().match(argv) | |
| 445 | - | pot_arguments = [a for a in formal_pattern.flat | |
| 446 | - | if type(a) in [Argument, Command]] | |
| 447 | 444 | if matched and left == []: # better message if left? | |
| 445 | + | options = [o for o in argv if type(o) is Option] | |
| 446 | + | pot_arguments = [a for a in formal_pattern.flat | |
| 447 | + | if type(a) in [Argument, Command]] | |
| 448 | 448 | return Dict((a.name, a.value) for a in | |
| 449 | 449 | (pot_options + options + pot_arguments + arguments)) | |
| 450 | 450 | raise DocoptExit() | |
The check that tells the two apart
fail→pass·test_docopt.py::test_long_options_error_handling
Check file test_docopt.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it1d9152082fa7b6d3fae43b45ac216f716f1cd53f
Broken version dated2012-06-11
Moduledocopt
Units changeddocopt, extras
Fingerprinte8fa0c56303b6a19
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.