Skip to content

Commit 06e806a

Browse files
committed
Made the owner parameter for __get__ optional in both BoundCommandFunc and UnboundCommand func
Also: - Restored the simple attribute definition for `__name__` attribute in BoundCommandFunc and UnboundCommandFund
1 parent c19c018 commit 06e806a

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

‎cmd2/annotated.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def do_build(self, target: str, common: CommonArgs):
311311
from .rich_utils import Cmd2HelpFormatter, HelpContent
312312
from .types import (
313313
BoundCommandFunc,
314+
CmdOrSet,
314315
CmdOrSetT,
315316
UnboundChoicesProvider,
316317
UnboundCommandFunc,
@@ -321,7 +322,7 @@ def do_build(self, target: str, common: CommonArgs):
321322
_NargsValue = int | str | tuple[int] | tuple[int, int] | tuple[int, float]
322323

323324

324-
_CommandFunc: TypeAlias = BoundCommandFunc | UnboundCommandFunc[CmdOrSetT, Any]
325+
_CommandFunc: TypeAlias = BoundCommandFunc | UnboundCommandFunc[CmdOrSet, Any]
325326

326327

327328
class Cmd2ParserKwargs(TypedDict, total=False):

‎cmd2/types.py‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@
7272
class BoundCommandFunc(Protocol):
7373
"""Protocol for a command function bound to a command instance."""
7474

75+
__name__: str
7576
__qualname__: str
7677

77-
@property
78-
def __name__(self) -> str:
79-
"""The name of the bound command function."""
80-
...
81-
8278
def __call__(self, *args: Any, **kwargs: Any) -> bool | None:
8379
"""Invoke the bound command function."""
8480

@@ -88,22 +84,18 @@ def __call__(self, *args: Any, **kwargs: Any) -> bool | None:
8884
class UnboundCommandFunc(Protocol[CmdOrSetT, P]):
8985
"""Protocol for an unbound command function."""
9086

87+
__name__: str
9188
__qualname__: str
9289

93-
@property
94-
def __name__(self) -> str:
95-
"""The name of the unbound command function."""
96-
...
97-
9890
def __call__(self, __self: CmdOrSetT, /, *args: P.args, **kwargs: P.kwargs) -> bool | None:
9991
"""Invoke the unbound command function with its command instance."""
10092
...
10193

10294
@overload
103-
def __get__(self, instance: None, owner: Any) -> "UnboundCommandFunc[CmdOrSetT, P]": ...
95+
def __get__(self, instance: None, owner: Any = ...) -> "UnboundCommandFunc[CmdOrSetT, P]": ...
10496

10597
@overload
106-
def __get__(self, instance: CmdOrSetT, owner: Any) -> BoundCommandFunc: ...
98+
def __get__(self, instance: CmdOrSetT, owner: Any = ...) -> BoundCommandFunc: ...
10799

108100

109101
##################################################################################################

0 commit comments

Comments
 (0)