Skip to content

v4.9.0

Choose a tag to compare

@BrianPugh BrianPugh released this 13 Mar 13:43
ead1504

Features

  • Parameter.consume_multiple now accepts int or tuple[int, int] for min/max element bounds.

    • An int sets a minimum (e.g. consume_multiple=2 requires at least 2 values).
    • A tuple sets both bounds (e.g. consume_multiple=(1, 3) requires 1–3 values).
    • Violations raise ConsumeMultipleError.
    # Require 1–3 space-separated values: --files a.txt b.txt c.txt
    files: Annotated[list[str], Parameter(consume_multiple=(1, 3))]

    By @BrianPugh in #764

  • New field Parameter.allow_repeating controls whether an option can be specified multiple times.

    • False raises RepeatArgumentError on repeat (useful with consume_multiple).
    • True allows repeats for any type; scalars use last-wins semantics.
    • None (default) preserves existing behavior: lists accumulate, scalars error.
    # Allow --files a b c, but not --files a --files b
    files: Annotated[list[str], Parameter(consume_multiple=True, allow_repeating=False)]
    # Last value wins: --color red --color blue → "blue"
    color: Annotated[str, Parameter(allow_repeating=True)]

    By @BrianPugh in #768

  • New field App.help_prologue displays text before the "Usage" line in help output.
    Inherited by subcommands; override per-command or set to "" to disable.

    app = App(help_prologue="myapp v1.0.0 — https://example.com")

    By @tahv in #769

Bug Fixes

  • Positional-only list parameters no longer consume tokens that appear after interleaved keyword arguments. a b --bar 8 d now correctly errors instead of silently assigning d to the positional list. By @BrianPugh in #766

Other

New Contributors

  • @tahv made their first contribution in #769

Full Changelog: v4.8.0...v4.9.0