Skip to content

Commit 8716321

Browse files
committed
[FIX] odev: parsing of unknown arguments in python 3.12.7+
See: python/cpython#59317
1 parent 9bff779 commit 8716321

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.github/workflows/odev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
runs-on: ${{ matrix.os }}-latest
103103

104104
strategy:
105-
fail-fast: true
105+
fail-fast: false
106106
matrix:
107107
os:
108108
- ubuntu

odev/common/commands/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ def prepare_arguments(cls, parser: ArgumentParser) -> None:
238238

239239
if params.get("nargs") == "*...":
240240
cls._unknown_arguments_dest = aliases[0]
241-
params["nargs"] = "*"
241+
242+
# A bug in standard library argparse before python 3.12.7 causes `...` to not work as expected
243+
# when used in conjunction with positional and optional arguments.
244+
# See: https://github.com/python/cpython/issues/59317
245+
params["nargs"] = "*" if sys.version_info < (3, 12, 7) else "..."
242246

243247
if "action" in params:
244248
params["action"] = ACTIONS_MAPPING.get(params["action"], params["action"])
@@ -281,7 +285,11 @@ def parse_arguments(cls, argv: Sequence[str]) -> Namespace:
281285
arguments = parser.parse_args(argv)
282286
else:
283287
arguments, unknown = parser.parse_known_args(argv)
284-
setattr(arguments, cls._unknown_arguments_dest, unknown)
288+
setattr(
289+
arguments,
290+
cls._unknown_arguments_dest,
291+
getattr(arguments, cls._unknown_arguments_dest, []) + unknown,
292+
)
285293
except SystemExit as exception:
286294
error_message = stderr.getvalue()
287295
error = re.search(rf"{cls._name}: error: (.*)$", error_message, re.MULTILINE)

0 commit comments

Comments
 (0)