Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mypy for cli package #19912

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions airflow/cli/commands/cheat_sheet_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from airflow.cli.cli_parser import ActionCommand, GroupCommand, airflow_commands
from airflow.cli.simple_table import AirflowConsole, SimpleTable
from airflow.utils.cli import suppress_logs_and_warning
from airflow.utils.helpers import partition


@suppress_logs_and_warning
Expand All @@ -38,8 +37,13 @@ def display_recursive(
):
actions: List[ActionCommand]
groups: List[GroupCommand]
actions_iter, groups_iter = partition(lambda x: isinstance(x, GroupCommand), commands)
actions, groups = list(actions_iter), list(groups_iter)
actions: List[ActionCommand] = []
groups: List[GroupCommand] = []
for command in commands:
if isinstance(command, GroupCommand):
groups.append(command)
else:
actions.append(command)

console = AirflowConsole()
if actions:
Expand Down
8 changes: 4 additions & 4 deletions airflow/cli/commands/info_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def process_url(self, value) -> str:
class NullAnonymizer(Anonymizer):
"""Do nothing."""

def _identity(self, value):
def _identity(self, value) -> str:
return value

process_path = process_username = process_url = _identity
Expand All @@ -70,19 +70,19 @@ def __init__(self):
username = getuser()
self._path_replacements = {home_path: "${HOME}", username: "${USER}"}

def process_path(self, value):
def process_path(self, value) -> str:
if not value:
return value
for src, target in self._path_replacements.items():
value = value.replace(src, target)
return value

def process_username(self, value):
def process_username(self, value) -> str:
if not value:
return value
return value[0] + "..." + value[-1]

def process_url(self, value):
def process_url(self, value) -> str:
if not value:
return value

Expand Down
8 changes: 4 additions & 4 deletions airflow/cli/simple_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def print_as_plain_table(self, data: List[Dict]):
self.print("No data found")
return
rows = [d.values() for d in data]
output = tabulate(rows, tablefmt="plain", headers=data[0].keys())
output = tabulate(rows, tablefmt="plain", headers=list(data[0].keys()))
print(output)

def _normalize_data(self, value: Any, output: str) -> Optional[Union[list, str, dict]]:
if isinstance(value, (tuple, list)):
if output == "table":
return ",".join(self._normalize_data(x, output) for x in value)
return ",".join(str(self._normalize_data(x, output)) for x in value)
return [self._normalize_data(x, output) for x in value]
if isinstance(value, dict) and output != "table":
return {k: self._normalize_data(v, output) for k, v in value.items()}
Expand All @@ -88,7 +88,7 @@ def _normalize_data(self, value: Any, output: str) -> Optional[Union[list, str,

def print_as(self, data: List[Union[Dict, Any]], output: str, mapper: Optional[Callable] = None):
"""Prints provided using format specified by output argument"""
output_to_renderer = {
output_to_renderer: Dict[str, Callable[[Any], None]] = {
"json": self.print_as_json,
"yaml": self.print_as_yaml,
"table": self.print_as_table,
Expand All @@ -106,7 +106,7 @@ def print_as(self, data: List[Union[Dict, Any]], output: str, mapper: Optional[C
if mapper:
dict_data: List[Dict] = [mapper(d) for d in data]
else:
dict_data: List[Dict] = data
dict_data = data
dict_data = [{k: self._normalize_data(v, output) for k, v in d.items()} for d in dict_data]
renderer(dict_data)

Expand Down