From 11a86e5653fcf54e08ca808d4acdf2c2df4d980d Mon Sep 17 00:00:00 2001 From: Eric Lin Date: Thu, 30 Jul 2020 16:31:25 -0400 Subject: Fixes to how command callables are filtered from CommandSet --- cmd2/cmd2.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'cmd2') diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 3f1696cf..8c9d40b8 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -426,7 +426,7 @@ class Cmd(cmd.Cmd): cmdset.on_register(self) methods = inspect.getmembers( cmdset, - predicate=lambda meth: (inspect.ismethod(meth) or isinstance(meth, Callable)) + predicate=lambda meth: isinstance(meth, Callable) and hasattr(meth, '__name__') and meth.__name__.startswith(COMMAND_FUNC_PREFIX)) installed_attributes = [] @@ -511,7 +511,8 @@ class Cmd(cmd.Cmd): methods = inspect.getmembers( cmdset, - predicate=lambda meth: inspect.ismethod(meth) and meth.__name__.startswith(COMMAND_FUNC_PREFIX)) + predicate=lambda meth: isinstance(meth, Callable) + and hasattr(meth, '__name__') and meth.__name__.startswith(COMMAND_FUNC_PREFIX)) for method in methods: cmd_name = method[0][len(COMMAND_FUNC_PREFIX):] @@ -538,7 +539,7 @@ class Cmd(cmd.Cmd): # find all methods that start with the subcommand prefix methods = inspect.getmembers( cmdset, - predicate=lambda meth: (inspect.ismethod(meth) or isinstance(meth, Callable)) + predicate=lambda meth: isinstance(meth, Callable) and hasattr(meth, constants.SUBCMD_ATTR_NAME) and hasattr(meth, constants.SUBCMD_ATTR_COMMAND) and hasattr(meth, constants.CMD_ATTR_ARGPARSER) @@ -583,7 +584,7 @@ class Cmd(cmd.Cmd): # find all methods that start with the subcommand prefix methods = inspect.getmembers( cmdset, - predicate=lambda meth: (inspect.ismethod(meth) or isinstance(meth, Callable)) + predicate=lambda meth: isinstance(meth, Callable) and hasattr(meth, constants.SUBCMD_ATTR_NAME) and hasattr(meth, constants.SUBCMD_ATTR_COMMAND) and hasattr(meth, constants.CMD_ATTR_ARGPARSER) -- cgit v1.2.1