cmd2 icon indicating copy to clipboard operation
cmd2 copied to clipboard

parameterize type declaration of with_default_category

Open analog-cbarber opened this issue 1 year ago • 1 comments

The current type signature of with_default_category is:

def with_default_category(category: str, *, heritable: bool = True) -> Callable[[Type['CommandSet']], Type['CommandSet']]:

as a result, type analyzers such as pyright may treat the decorated class as if it is just a CommandSet rather than an actual subclass. Instead, the decorator should use a type variable. I think something along these lines might work:

CS = TypeVar("CS", bound=Type[CommandSet])

def with_default_category(category: str, *, heritable: bool = True) -> Callable[[CS], CS]:

analog-cbarber avatar Jun 14 '24 17:06 analog-cbarber