Skip to content

Template functionality for argument blocks using with_annotaed decorator #1689

Description

@neoniobium

Feature Request

To avoid redundant code, add a template mechanism for argument blocks that appear in multiple commands. Using the with_argparse decorator this is easy by reusing a function that modifies a parser; with_annotated currently has no simple equivalent.

Possible solutions

  • Use a TypedDict + Unpack to reuse a named block of annotations:
class ArgumentBlock(TypedDict):
    # define reusable keys/values here
    ...

class App(Cmd):

    @with_annotated
    def do_a(..., **kwargs: Unpack[ArgumentBlock]) -> None:
        ...

    @with_annotated
    def do_b(..., **kwargs: Unpack[ArgumentBlock]) -> None:
        ...
  • Allow attaching a predefined parser to the parser generated by with_annotated, and expose the resulting namespace inside the decorated method for easy access.

Both approaches reduce duplication; the second may be simpler to implement.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions