|
4 | 4 | import argparse |
5 | 5 | from collections.abc import Mapping |
6 | 6 | from collections.abc import Sequence |
7 | | -from gettext import gettext |
8 | 7 | import os |
9 | | -import sys |
10 | 8 | from typing import Any |
11 | 9 | from typing import Callable |
12 | 10 | from typing import cast |
@@ -446,44 +444,6 @@ def parse_args( # type: ignore |
446 | 444 | getattr(parsed, FILE_OR_DIR).extend(unrecognized) |
447 | 445 | return parsed |
448 | 446 |
|
449 | | - if sys.version_info < (3, 9): # pragma: no cover |
450 | | - # Backport of https://github.com/python/cpython/pull/14316 so we can |
451 | | - # disable long --argument abbreviations without breaking short flags. |
452 | | - def _parse_optional( |
453 | | - self, arg_string: str |
454 | | - ) -> tuple[argparse.Action | None, str, str | None] | None: |
455 | | - if not arg_string: |
456 | | - return None |
457 | | - if arg_string[0] not in self.prefix_chars: |
458 | | - return None |
459 | | - if arg_string in self._option_string_actions: |
460 | | - action = self._option_string_actions[arg_string] |
461 | | - return action, arg_string, None |
462 | | - if len(arg_string) == 1: |
463 | | - return None |
464 | | - if "=" in arg_string: |
465 | | - option_string, explicit_arg = arg_string.split("=", 1) |
466 | | - if option_string in self._option_string_actions: |
467 | | - action = self._option_string_actions[option_string] |
468 | | - return action, option_string, explicit_arg |
469 | | - if self.allow_abbrev or not arg_string.startswith("--"): |
470 | | - option_tuples = self._get_option_tuples(arg_string) |
471 | | - if len(option_tuples) > 1: |
472 | | - msg = gettext( |
473 | | - "ambiguous option: %(option)s could match %(matches)s" |
474 | | - ) |
475 | | - options = ", ".join(option for _, option, _ in option_tuples) |
476 | | - self.error(msg % {"option": arg_string, "matches": options}) |
477 | | - elif len(option_tuples) == 1: |
478 | | - (option_tuple,) = option_tuples |
479 | | - return option_tuple |
480 | | - if self._negative_number_matcher.match(arg_string): |
481 | | - if not self._has_negative_number_optionals: |
482 | | - return None |
483 | | - if " " in arg_string: |
484 | | - return None |
485 | | - return None, arg_string, None |
486 | | - |
487 | 447 |
|
488 | 448 | class DropShorterLongHelpFormatter(argparse.HelpFormatter): |
489 | 449 | """Shorten help for long options that differ only in extra hyphens. |
|
0 commit comments