Skip to content

Commit 9f1d162

Browse files
committed
Merge branch 'master' into 3.0.0
2 parents e0054eb + 91897f4 commit 9f1d162

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
* Added `RawDescriptionCmd2HelpFormatter`, `RawTextCmd2HelpFormatter`, `ArgumentDefaultsCmd2HelpFormatter`,
1111
and `MetavarTypeCmd2HelpFormatter` and they all use `rich-argparse`.
1212

13+
## 2.5.6 (November 14, 2024)
14+
* Bug Fixes
15+
* Fixed type hint for `with_default_category` decorator which caused type checkers to mistype
16+
a subclass of `CommandSet` as a plain `CommandSet`.
17+
1318
## 2.5.5 (November 13, 2024)
1419
* Bug Fixes
1520
* Fixed type hints for passing a class method to `with_argparser` and `as_subcommand_to`.

cmd2/command_definition.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Mapping,
1010
Optional,
1111
Type,
12+
TypeVar,
1213
)
1314

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

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

33-
def with_default_category(category: str, *, heritable: bool = True) -> Callable[[Type['CommandSet']], Type['CommandSet']]:
35+
36+
def with_default_category(category: str, *, heritable: bool = True) -> Callable[[CommandSetType], CommandSetType]:
3437
"""
3538
Decorator that applies a category to all ``do_*`` command methods in a class that do not already
3639
have a category specified.
@@ -41,15 +44,15 @@ def with_default_category(category: str, *, heritable: bool = True) -> Callable[
4144
override the default category.
4245
4346
If `heritable` is set to False, then only the commands declared locally to this CommandSet will be placed in the
44-
specified category. Dynamically created commands, and commands declared in sub-classes will not receive this
47+
specified category. Dynamically created commands and commands declared in sub-classes will not receive this
4548
category.
4649
4750
:param category: category to put all uncategorized commands in
4851
:param heritable: Flag whether this default category should apply to sub-classes. Defaults to True
4952
:return: decorator function
5053
"""
5154

52-
def decorate_class(cls: Type[CommandSet]) -> Type[CommandSet]:
55+
def decorate_class(cls: CommandSetType) -> CommandSetType:
5356
if heritable:
5457
setattr(cls, CLASS_ATTR_DEFAULT_HELP_CATEGORY, category)
5558

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
nitpick_ignore = [
185185
('py:class', 'ArgparseCommandFunc'),
186186
('py:class', 'argparse._SubParsersAction'),
187+
('py:class', 'cmd2.command_definition.CommandSetType'),
187188
('py:class', 'cmd2.decorators.CommandParent'),
188189
('py:class', 'cmd2.decorators.CommandParentType'),
189190
('py:class', 'cmd2.utils._T'),

0 commit comments

Comments
 (0)