diff options
author | Eric Lin <anselor@gmail.com> | 2020-07-30 16:31:25 -0400 |
---|---|---|
committer | anselor <anselor@gmail.com> | 2020-08-04 13:38:08 -0400 |
commit | 11a86e5653fcf54e08ca808d4acdf2c2df4d980d (patch) | |
tree | 0bcb49a07f78f114146512c8373ed397c7eb6402 /cmd2/cmd2.py | |
parent | 13bac58aaf823fda85d9eb60bbb47b3f920792c7 (diff) | |
download | cmd2-git-11a86e5653fcf54e08ca808d4acdf2c2df4d980d.tar.gz |
Fixes to how command callables are filtered from CommandSet
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 9 |
1 files changed, 5 insertions, 4 deletions
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) |