|
1 | 1 | # Annotated Argument Processing |
2 | 2 |
|
3 | | -!!! warning "Experimental" |
4 | | - |
5 | | - The `@with_annotated` decorator and its supporting `Argument` / `Option` metadata classes are |
6 | | - **experimental**. The public API, the surface of accepted type annotations, and the generated |
7 | | - argparse behavior may all change in future releases without a deprecation cycle. Pin a specific |
8 | | - `cmd2` version if you depend on the exact current semantics, and expect to revisit your usage on |
9 | | - upgrades. |
10 | | - |
11 | | - For production code that needs stable behavior, use |
12 | | - [@with_argparser](argument_processing.md#with_argparser-decorator) instead. |
13 | | - |
14 | 3 | The [@with_annotated][cmd2.with_annotated] decorator builds an argparse parser automatically from |
15 | 4 | the decorated function's type annotations. No manual `add_argument()` calls are required, and the |
16 | 5 | command body receives typed keyword arguments directly instead of an `argparse.Namespace`. |
@@ -45,9 +34,8 @@ The two decorators are interchangeable -- here is the same command written both |
45 | 34 |
|
46 | 35 | The annotated version is more concise, gives you typed parameters, and supports several advanced |
47 | 36 | cmd2 features directly, including `ns_provider`, `with_unknown_args`, and typed subcommands. Pick |
48 | | -`@with_argparser` when you need a stable, well-established API or fine-grained control over the |
49 | | -parser; pick `@with_annotated` when you want type-hint-driven ergonomics and can accept the |
50 | | -experimental status. |
| 37 | +`@with_argparser` when you want direct control over the parser or already have one; pick |
| 38 | +`@with_annotated` when you want type-hint-driven ergonomics. |
51 | 39 |
|
52 | 40 | ## Basic usage |
53 | 41 |
|
@@ -815,16 +803,3 @@ Specifically: |
815 | 803 |
|
816 | 804 | With `@with_argparser`, provide `choices`, `choices_provider`, or `completer` explicitly when you |
817 | 805 | want completion behavior. |
818 | | - |
819 | | -## Stability and feedback |
820 | | - |
821 | | -Because this feature is experimental: |
822 | | - |
823 | | -- Behavior of edge cases (mixed-type tuples, deeply-nested `Annotated`, conflicting metadata) may |
824 | | - change. |
825 | | -- Diagnostic error messages may be reworded. |
826 | | -- The set of supported type annotations may be expanded or trimmed. |
827 | | - |
828 | | -If you depend on `@with_annotated`, please share feedback and edge cases via the |
829 | | -[issue tracker](https://github.com/python-cmd2/cmd2/issues) so behavior can be locked in before the |
830 | | -feature graduates out of experimental. |
0 commit comments