Skip to content

conditional inheritance ? #120

Answered by DanCardin
euri10 asked this question in Q&A
Jun 10, 2024 · 4 comments · 14 replies
Discussion options

You must be logged in to vote

Something else that just occurred to me again, is that Subcommands[A, B] == Annotated[A | B, Subcommand()] and Subcommand() is short for Subcommand(options={'a': Command(...), 'b': Command(...)})

So you can get more custom/fancier by actually supplying your own options to overrride the default behavior.

This is a fully contained example you could run to see if it gives you the desired behavior. And you can then lean more into or further out of the DRY ness as needed.

from __future__ import annotations

from dataclasses import dataclass
from typing import Annotated

import cappa


@dataclass
class Command:
    website: cappa.Subcommands[Google | Bing]


@cappa.command()
class GoogleArgs:
    

Replies: 4 comments 14 replies

Comment options

You must be logged in to vote
1 reply
@euri10
Comment options

Comment options

You must be logged in to vote
11 replies
@DanCardin
Comment options

@euri10
Comment options

@DanCardin
Comment options

@DanCardin
Comment options

Answer selected by euri10
@euri10
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@DanCardin
Comment options

@euri10
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants