argparsing: remove "map_long_option" Action attribute support
This feature was added in commit
007a77c2ba
, but was never used in pytest
itself. A GitHub code search doesn't find any users either (only pytest
repo copies). It seems safe to clean up.
This commit is contained in:
parent
5b3867fd65
commit
51f9cd0e02
|
@ -409,8 +409,6 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
|
|||
"""shorten help for long options that differ only in extra hyphens
|
||||
|
||||
- collapse **long** options that are the same except for extra hyphens
|
||||
- special action attribute map_long_option allows suppressing additional
|
||||
long options
|
||||
- shortcut if there are only two options and one of them is a short one
|
||||
- cache result on action object as this is called at least 2 times
|
||||
"""
|
||||
|
@ -434,9 +432,6 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
|
|||
action._formatted_action_invocation = orgstr
|
||||
return orgstr
|
||||
return_list = []
|
||||
option_map = getattr(action, "map_long_option", {})
|
||||
if option_map is None:
|
||||
option_map = {}
|
||||
short_long = {} # type: Dict[str, str]
|
||||
for option in options:
|
||||
if len(option) == 2 or option[2] == " ":
|
||||
|
@ -446,12 +441,11 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
|
|||
'long optional argument without "--": [%s]' % (option), self
|
||||
)
|
||||
xxoption = option[2:]
|
||||
if xxoption.split()[0] not in option_map:
|
||||
shortened = xxoption.replace("-", "")
|
||||
if shortened not in short_long or len(short_long[shortened]) < len(
|
||||
xxoption
|
||||
):
|
||||
short_long[shortened] = xxoption
|
||||
shortened = xxoption.replace("-", "")
|
||||
if shortened not in short_long or len(short_long[shortened]) < len(
|
||||
xxoption
|
||||
):
|
||||
short_long[shortened] = xxoption
|
||||
# now short_long has been filled out to the longest with dashes
|
||||
# **and** we keep the right option ordering from add_argument
|
||||
for option in options:
|
||||
|
|
|
@ -205,11 +205,11 @@ class TestParser:
|
|||
)
|
||||
parser.add_argument(
|
||||
"-t", "--twoword", "--duo", "--two-word", "--two", help="foo"
|
||||
).map_long_option = {"two": "two-word"}
|
||||
)
|
||||
# throws error on --deux only!
|
||||
parser.add_argument(
|
||||
"-d", "--deuxmots", "--deux-mots", action="store_true", help="foo"
|
||||
).map_long_option = {"deux": "deux-mots"}
|
||||
)
|
||||
parser.add_argument("-s", action="store_true", help="single short")
|
||||
parser.add_argument("--abc", "-a", action="store_true", help="bar")
|
||||
parser.add_argument("--klm", "-k", "--kl-m", action="store_true", help="bar")
|
||||
|
@ -221,7 +221,7 @@ class TestParser:
|
|||
)
|
||||
parser.add_argument(
|
||||
"-x", "--exit-on-first", "--exitfirst", action="store_true", help="spam"
|
||||
).map_long_option = {"exitfirst": "exit-on-first"}
|
||||
)
|
||||
parser.add_argument("files_and_dirs", nargs="*")
|
||||
args = parser.parse_args(["-k", "--duo", "hallo", "--exitfirst"])
|
||||
assert args.twoword == "hallo"
|
||||
|
|
Loading…
Reference in New Issue