An argparse wrapper that doesn't make you say "argh" each time you deal with it.
GNU Lesser General Public License v3.0
369
stars
56
forks
source link
Type hints: basic usage to infer argument types (fixes #203) #211
Closed
neithere closed 11 months ago
MVP:
str
,int
,float
(and their deprecated aliases:Str
, etc. until we drop support for Python 3.8 around Q4 2024)Nice to have:
nargs=ZERO_OR_MORE
:list[str]
→nargs=ZERO_OR_MORE, type=str
list[str] | None
,list[str | None]
andlist[str | None] | None
— there's no difference for us in the context of mapping).nargs=N
foo: Tuple[str, int, float]
->add_argument('foo', nargs=3)
followed by (e.g.)args = parser.parse_args(); args.foo[1] = int(args.foo[1]); args.foo[2] = float(args.foo[2])
(https://github.com/neithere/argh/issues/107#issuecomment-843334649)foo: Literal['one', 'two', 'three']
->add_argument('foo', choices=['one', 'two', 'three']
possibly with completion (later). (https://github.com/neithere/argh/issues/107#issuecomment-843334649)add_argument()
params via hints instead of@arg
:Annotated[x, ExtraParams(type=some_callable, help="something", nargs="+")]