Skip to content

Commit 7a97e44

Browse files
committed
Refactor _get_ui_plugins to use specific TypedDict types for better type safety
1 parent f1ab532 commit 7a97e44

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

airflow-core/src/airflow/plugins_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __register_plugins(plugin_instances: list[AirflowPlugin], errors: dict[str,
142142

143143

144144
@cache
145-
def _get_ui_plugins() -> tuple[list[Any], list[Any]]:
145+
def _get_ui_plugins() -> tuple[list[ExternalViewDict], list[ReactAppDict]]:
146146
"""Collect extension points for the UI."""
147147
log.debug("Initialize UI plugin")
148148

shared/plugins_manager/src/airflow_shared/plugins_manager/plugins_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class AirflowPluginException(Exception):
8787
"""Exception when loading plugin."""
8888

8989

90+
# Kept in sync with ``BaseDestinationLiteral`` in ``airflow.api_fastapi.core_api.datamodels.plugins``
91+
BaseDestinationLiteral = Literal["nav", "dag", "dag_run", "task", "task_instance", "asset", "base"]
92+
93+
9094
class _BaseUIDict(TypedDict):
9195
"""Shared UI fields mirroring ``BaseUIResponse``."""
9296

@@ -102,14 +106,14 @@ class ExternalViewDict(_BaseUIDict):
102106
"""Dictionary structure for entries in AirflowPlugin.external_views."""
103107

104108
href: str
105-
destination: NotRequired[Literal["nav", "dag", "dag_run", "task", "task_instance", "base"]]
109+
destination: NotRequired[BaseDestinationLiteral]
106110

107111

108112
class ReactAppDict(_BaseUIDict):
109113
"""Dictionary structure for entries in AirflowPlugin.react_apps."""
110114

111115
bundle_url: str
112-
destination: NotRequired[Literal["nav", "dag", "dag_run", "task", "task_instance", "base", "dashboard"]]
116+
destination: NotRequired[Literal[BaseDestinationLiteral, "dashboard", "dag_overview", "task_overview"]]
113117

114118

115119
class FastAPIAppDict(TypedDict):

0 commit comments

Comments
 (0)