Skip to content

Commit

Permalink
Fix mypy issue with callable
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed May 18, 2021
1 parent e451369 commit aefd907
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Expand Up @@ -88,8 +88,7 @@ repos:
- enrich
- flaky
- pytest
# https://github.com/willmcgugan/rich/discussions/1243
- rich>=9.5.1,<10.2
- rich>=10.2.1
- ruamel.yaml
- tenacity
- types-PyYAML
Expand Down
10 changes: 7 additions & 3 deletions src/ansiblelint/__main__.py
Expand Up @@ -28,7 +28,7 @@
import sys
from argparse import Namespace
from contextlib import contextmanager
from typing import TYPE_CHECKING, Iterator, List, Optional
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Optional

from enrich.console import should_do_markup

Expand Down Expand Up @@ -192,14 +192,18 @@ def main(argv: Optional[List[str]] = None) -> int:

# On purpose lazy-imports to avoid pre-loading Ansible
# pylint: disable=import-outside-toplevel
from ansiblelint.generate_docs import rules_as_rich, rules_as_rst
from ansiblelint.generate_docs import rules_as_rich, rules_as_rst, rules_as_str
from ansiblelint.rules import RulesCollection

rules = RulesCollection(options.rulesdirs)

if options.listrules:

_rule_format_map = {'plain': str, 'rich': rules_as_rich, 'rst': rules_as_rst}
_rule_format_map: Dict[str, Callable[..., Any]] = {
'plain': rules_as_str,
'rich': rules_as_rich,
'rst': rules_as_rst,
}

console.print(_rule_format_map[options.format](rules), highlight=False)
return 0
Expand Down
4 changes: 4 additions & 0 deletions src/ansiblelint/generate_docs.py
Expand Up @@ -25,6 +25,10 @@
_logger = logging.getLogger(__name__)


def rules_as_str(rules: RulesCollection) -> str:
return str(rules)


def rules_as_rst(rules: RulesCollection) -> str:
"""Return RST documentation for a list of rules."""
r = DOC_HEADER
Expand Down

0 comments on commit aefd907

Please sign in to comment.