Skip to content

Commit 96224cf

Browse files
committed
Updated documentation for the CommandSet._cmd property.
1 parent 0d22fc9 commit 96224cf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cmd2/command_definition.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,17 @@ def _cmd(self) -> 'cmd2.Cmd':
102102
Using this property ensures that self.__cmd_internal has been set
103103
and it tells type checkers that it's no longer a None type.
104104
105-
Override this property if you need to change its return type to a
106-
child class of Cmd.
105+
Override this property to specify a more specific return type for static
106+
type checking. The typing.cast function can be used to assert to the
107+
type checker that the parent cmd2.Cmd instance is of a more specific
108+
subclass, enabling better autocompletion and type safety in the child class.
109+
110+
For example:
111+
112+
@property
113+
def _cmd(self) -> CustomCmdApp:
114+
return cast(CustomCmdApp, super()._cmd)
115+
107116
108117
:raises CommandSetRegistrationError: if CommandSet is not registered.
109118
"""

0 commit comments

Comments
 (0)