This is an automated email from the ASF dual-hosted git repository.

ephraimanierobi pushed a commit to branch v2-7-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 99aaacbd64c40dbbb825cb2cf9d1db911d5ce180
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Mon Aug 7 18:52:13 2023 +0000

    Refactor: Simplify dict manipulation in airflow/cli (#33159)
    
    (cherry picked from commit c074a1ecd946b2ad0f85be62aa977c269e2ffb83)
---
 airflow/cli/cli_parser.py                | 5 +----
 airflow/cli/commands/provider_command.py | 4 ++--
 airflow/cli/commands/role_command.py     | 4 ++--
 airflow/cli/simple_table.py              | 8 +++-----
 4 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/airflow/cli/cli_parser.py b/airflow/cli/cli_parser.py
index 669c77ea40..3e1e2bd5c1 100644
--- a/airflow/cli/cli_parser.py
+++ b/airflow/cli/cli_parser.py
@@ -116,10 +116,7 @@ def get_parser(dag_parser: bool = False) -> 
argparse.ArgumentParser:
     subparsers.required = True
 
     command_dict = DAG_CLI_DICT if dag_parser else ALL_COMMANDS_DICT
-    subparser_list = command_dict.keys()
-    sub_name: str
-    for sub_name in sorted(subparser_list):
-        sub: CLICommand = command_dict[sub_name]
+    for _, sub in sorted(command_dict.items()):
         _add_command(subparsers, sub)
     return parser
 
diff --git a/airflow/cli/commands/provider_command.py 
b/airflow/cli/commands/provider_command.py
index a55032d9f2..76e81a1054 100644
--- a/airflow/cli/commands/provider_command.py
+++ b/airflow/cli/commands/provider_command.py
@@ -106,7 +106,7 @@ def triggers_list(args):
 def connection_form_widget_list(args):
     """Lists all custom connection form fields at the command line."""
     AirflowConsole().print_as(
-        data=list(sorted(ProvidersManager().connection_form_widgets.items())),
+        data=sorted(ProvidersManager().connection_form_widgets.items()),
         output=args.output,
         mapper=lambda x: {
             "connection_parameter_name": x[0],
@@ -122,7 +122,7 @@ def connection_form_widget_list(args):
 def connection_field_behaviours(args):
     """Lists field behaviours."""
     AirflowConsole().print_as(
-        data=list(ProvidersManager().field_behaviours.keys()),
+        data=list(ProvidersManager().field_behaviours),
         output=args.output,
         mapper=lambda x: {
             "field_behaviours": x,
diff --git a/airflow/cli/commands/role_command.py 
b/airflow/cli/commands/role_command.py
index 4e439fa2fc..180e2dd2a7 100644
--- a/airflow/cli/commands/role_command.py
+++ b/airflow/cli/commands/role_command.py
@@ -121,8 +121,8 @@ def __roles_add_or_remove_permissions(args):
                 exit(1)
 
         permission_count = 0
-        for (role_name, resource_name, action_name) in list(
-            itertools.product(args.role, args.resource, args.action or [None])
+        for role_name, resource_name, action_name in itertools.product(
+            args.role, args.resource, args.action or [None]
         ):
             res_key = (role_name, resource_name)
             if is_add and action_name not in perm_map[res_key]:
diff --git a/airflow/cli/simple_table.py b/airflow/cli/simple_table.py
index c2c60df95c..b9338eb6a3 100644
--- a/airflow/cli/simple_table.py
+++ b/airflow/cli/simple_table.py
@@ -64,7 +64,7 @@ class AirflowConsole(Console):
             return
 
         table = SimpleTable(show_header=self.show_header)
-        for col in data[0].keys():
+        for col in data[0]:
             table.add_column(col)
 
         for row in data:
@@ -77,7 +77,7 @@ class AirflowConsole(Console):
             self.print("No data found")
             return
         rows = [d.values() for d in data]
-        output = tabulate(rows, tablefmt="plain", headers=list(data[0].keys()))
+        output = tabulate(rows, tablefmt="plain", headers=list(data[0]))
         print(output)
 
     def _normalize_data(self, value: Any, output: str) -> list | str | dict | 
None:
@@ -108,9 +108,7 @@ class AirflowConsole(Console):
         }
         renderer = output_to_renderer.get(output)
         if not renderer:
-            raise ValueError(
-                f"Unknown formatter: {output}. Allowed options: 
{list(output_to_renderer.keys())}"
-            )
+            raise ValueError(f"Unknown formatter: {output}. Allowed options: 
{list(output_to_renderer)}")
 
         if mapper:
             dict_data: Sequence[dict] = [mapper(d) for d in data]

Reply via email to