-
Just a tiny un-intuitive thing. If I specify an optional subcommand like that: subcommand: Annotated[
cappa.Subcommands[Subcommand1 | Subcommand2] | None,
] = None ...trying to call the parent command ( % prog command
prog: error: Invalid value for 'subcommand': Possible variants
- Union[Subcommand1, Subcommand2]: Possible variants
- Subcommand1: Subcommand1.__init__() takes 1 positional argument but 2 were given
- Subcommand2: Subcommand2.__init__() takes 1 positional argument but 2 were given
- <no value> (I'm using The correct way to annotate the subcommand is to put subcommand: Annotated[
cappa.Subcommands[Subcommand1 | Subcommand2 | None],
] = None ...which makes sense, since Subcommands: TypeAlias = Annotated[T, Subcommand] ...and seems to make type-checkers happy anyway. I simply had to go back through comments I posted here to find out I had to put If there's an easy "fix" to support |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
As seen in #163, we can actually annotate the subcommand like this: subcommand: Annotated[
Subcommand1 | Subcommand2 | None,
cappa.Subcommand(),
] = None ...making this intuitive again 🙂 |
Beta Was this translation helpful? Give feedback.
As seen in #163, we can actually annotate the subcommand like this:
...making this intuitive again 🙂