Skip to content

Commit

Permalink
Merge branch 'master' into 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvanbrunt committed Nov 14, 2024
2 parents e0054eb + 91897f4 commit 9f1d162
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
* Added `RawDescriptionCmd2HelpFormatter`, `RawTextCmd2HelpFormatter`, `ArgumentDefaultsCmd2HelpFormatter`,
and `MetavarTypeCmd2HelpFormatter` and they all use `rich-argparse`.

## 2.5.6 (November 14, 2024)
* Bug Fixes
* Fixed type hint for `with_default_category` decorator which caused type checkers to mistype
a subclass of `CommandSet` as a plain `CommandSet`.

## 2.5.5 (November 13, 2024)
* Bug Fixes
* Fixed type hints for passing a class method to `with_argparser` and `as_subcommand_to`.
Expand Down
9 changes: 6 additions & 3 deletions cmd2/command_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Mapping,
Optional,
Type,
TypeVar,
)

from .constants import (
Expand All @@ -29,8 +30,10 @@
#: Further refinements are needed to define the input parameters
CommandFunc = Callable[..., Optional[bool]]

CommandSetType = TypeVar('CommandSetType', bound=Type['CommandSet'])

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

def with_default_category(category: str, *, heritable: bool = True) -> Callable[[CommandSetType], CommandSetType]:
"""
Decorator that applies a category to all ``do_*`` command methods in a class that do not already
have a category specified.
Expand All @@ -41,15 +44,15 @@ def with_default_category(category: str, *, heritable: bool = True) -> Callable[
override the default category.
If `heritable` is set to False, then only the commands declared locally to this CommandSet will be placed in the
specified category. Dynamically created commands, and commands declared in sub-classes will not receive this
specified category. Dynamically created commands and commands declared in sub-classes will not receive this
category.
:param category: category to put all uncategorized commands in
:param heritable: Flag whether this default category should apply to sub-classes. Defaults to True
:return: decorator function
"""

def decorate_class(cls: Type[CommandSet]) -> Type[CommandSet]:
def decorate_class(cls: CommandSetType) -> CommandSetType:
if heritable:
setattr(cls, CLASS_ATTR_DEFAULT_HELP_CATEGORY, category)

Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
nitpick_ignore = [
('py:class', 'ArgparseCommandFunc'),
('py:class', 'argparse._SubParsersAction'),
('py:class', 'cmd2.command_definition.CommandSetType'),
('py:class', 'cmd2.decorators.CommandParent'),
('py:class', 'cmd2.decorators.CommandParentType'),
('py:class', 'cmd2.utils._T'),
Expand Down

0 comments on commit 9f1d162

Please sign in to comment.