diff options
author | xNinjaKittyx <xNinjaKittyx@users.noreply.github.com> | 2020-12-15 17:21:33 -0800 |
---|---|---|
committer | xNinjaKittyx <xNinjaKittyx@users.noreply.github.com> | 2020-12-15 18:20:13 -0800 |
commit | 9aa54a5b27468d61337528cb1e1b5b9b11a80978 (patch) | |
tree | 567693115cc101efb9254a96d96d80e9f9ccd557 /cmd2/command_definition.py | |
parent | 03c65c60b39e369958b056c5c844d36d515c8a63 (diff) | |
download | cmd2-git-ci_improvements.tar.gz |
Adds pre-commit config to run various lintersci_improvements
This ads black, isort, pyupgrade, and flake8 to pre-commit-config.yaml
There are also some small changes to travis.yml and tasks.py to reduce
some repeated configurations that should be consolidated into
setup.cfg. Most other changes are automated by the linter scripts.
Diffstat (limited to 'cmd2/command_definition.py')
-rw-r--r-- | cmd2/command_definition.py | 14 |
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 |