Skip to content

Commit b51eb81

Browse files
v70 Improved help for variadic
1 parent 7e53d92 commit b51eb81

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

pydantic_argparse_next/parser/classes.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ def help_text(self) -> list[str]:
323323
req_args += ", {" f"arg{i}, ..."
324324

325325
if self.variadic_max_args < float("inf"):
326-
req_args += f", arg{self.variadic_max_args}" + "}"
326+
if i == self.variadic_max_args:
327+
req_args += ", {" + f"arg{self.variadic_max_args}" + "}"
328+
else:
329+
req_args += f", arg{self.variadic_max_args}" + "}"
327330
else:
328331
req_args += "}"
329332

@@ -350,7 +353,10 @@ def help_text(self) -> list[str]:
350353
req_args += ", {" f"arg{i}, ..."
351354

352355
if self.variadic_max_args < float("inf"):
353-
req_args += f", arg{self.variadic_max_args}" + "}"
356+
if i == self.variadic_max_args:
357+
req_args += ", {" + f"arg{self.variadic_max_args}" + "}"
358+
else:
359+
req_args += f", arg{self.variadic_max_args}" + "}"
354360
else:
355361
req_args += "}"
356362

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[project]
66
name = "pydantic-argparse-next"
7-
version = "1.0.6"
7+
version = "1.0.7"
88
description = "Pydantic 2 argparse."
99
readme = "README.md"
1010
requires-python = ">=3.11"

tests/help/test_help.py

+2
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,13 @@ class Test(BaseModel):
204204
b: tuple[str, int, float]
205205
c: tuple
206206
d: list[int] = pa.KwArg(n_args="2...6")
207+
e: list[str] = pa.KwArg(n_args="2...3")
207208

208209
output = read_output(Test, ["--help"], capsys).out
209210

210211
assert "LIST[STR] (arg1, {arg2, ...})" in output
211212
assert "TUPLE (arg1 STR, arg2 INT, arg3 FLOAT)" in output
212213
assert "TUPLE[STR] (arg1, {arg2, ...})" in output
213214
assert "LIST[INT] (arg1, arg2, {arg3, ..., arg6})" in output
215+
assert "LIST[STR] (arg1, arg2, {arg3})" in output
214216

0 commit comments

Comments
 (0)