summaryrefslogtreecommitdiff
path: root/cmd2/command_definition.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmd2/command_definition.py')
-rw-r--r--cmd2/command_definition.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/cmd2/command_definition.py b/cmd2/command_definition.py
index 3f05792c..0d6f7045 100644
--- a/cmd2/command_definition.py
+++ b/cmd2/command_definition.py
@@ -10,10 +10,11 @@ from .exceptions import CommandSetRegistrationError
# Allows IDEs to resolve types without impacting imports at runtime, breaking circular dependency issues
try: # pragma: no cover
from typing import TYPE_CHECKING
+
if TYPE_CHECKING:
import cmd2
-except ImportError: # pragma: no cover
+except ImportError: # pragma: no cover
pass
@@ -40,22 +41,27 @@ def with_default_category(category: str, *, heritable: bool = True):
if heritable:
setattr(cls, CLASS_ATTR_DEFAULT_HELP_CATEGORY, category)
- from .constants import CMD_ATTR_HELP_CATEGORY
import inspect
+
+ from .constants import CMD_ATTR_HELP_CATEGORY
from .decorators import with_category
+
# get members of the class that meet the following criteria:
# 1. Must be a function
# 2. Must start with COMMAND_FUNC_PREFIX (do_)
# 3. Must be a member of the class being decorated and not one inherited from a parent declaration
methods = inspect.getmembers(
cls,
- predicate=lambda meth: inspect.isfunction(meth) and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
- and meth in inspect.getmro(cls)[0].__dict__.values())
+ predicate=lambda meth: inspect.isfunction(meth)
+ and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
+ and meth in inspect.getmro(cls)[0].__dict__.values(),
+ )
category_decorator = with_category(category)
for method in methods:
if not hasattr(method[1], CMD_ATTR_HELP_CATEGORY):
setattr(cls, method[0], category_decorator(method[1]))
return cls
+
return decorate_class