From 55a3cda3320480f385128f1c92954219fe959597 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 6 Feb 2024 14:16:46 -0600 Subject: [PATCH] feat: strip trailing underscore from option names Fixes #222. --- src/argh/assembling.py | 3 +++ tests/test_assembling.py | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/argh/assembling.py b/src/argh/assembling.py index 7a690ea..cad4319 100644 --- a/src/argh/assembling.py +++ b/src/argh/assembling.py @@ -153,6 +153,9 @@ def infer_argspecs_from_function( ) def _make_cli_arg_names_options(arg_name) -> Tuple[List[str], List[str]]: + # str.removesuffix() can be used here starting with Python 3.9 + if arg_name.endswith("_"): + arg_name = arg_name[:-1] cliified_arg_name = arg_name.replace("_", "-") positionals = [cliified_arg_name] can_have_short_opt = arg_name[0] not in conflicting_opts diff --git a/tests/test_assembling.py b/tests/test_assembling.py index 6243513..f1dfd35 100644 --- a/tests/test_assembling.py +++ b/tests/test_assembling.py @@ -669,7 +669,6 @@ def cmd(foo_pos, bar_pos, *args, foo_kwonly="foo_kwonly", bar_kwonly): ] -@pytest.mark.xfail() def test_trailing_underscore_in_argument_name(): "Stripping trailing underscores from named options"