diff --git a/airflow-ctl/src/airflowctl/ctl/cli_config.py b/airflow-ctl/src/airflowctl/ctl/cli_config.py index 2b8e6d8bfd729..5e8302c3641d1 100644 --- a/airflow-ctl/src/airflowctl/ctl/cli_config.py +++ b/airflow-ctl/src/airflowctl/ctl/cli_config.py @@ -401,6 +401,12 @@ def __init__(self, file_path: str | Path | None = None): def _inspect_operations(self) -> None: """Parse file and return matching Operation Method with details.""" + def _union_members(node: ast.expr) -> list[str]: + """Get individual type names from a union type annotation.""" + if isinstance(node, ast.BinOp) and isinstance(node.op, ast.BitOr): + return _union_members(node.left) + _union_members(node.right) + return [ast.unparse(node)] + def get_function_details(node: ast.FunctionDef, parent_node: ast.ClassDef) -> dict: """Extract function name, arguments, and return annotation.""" func_name = node.name @@ -415,10 +421,7 @@ def get_function_details(node: ast.FunctionDef, parent_node: ast.ClassDef) -> di if node.returns: return_annotation = [ - t.strip() - # TODO change this while removing Python 3.9 support - for t in ast.unparse(node.returns).split("|") - if t.strip() != ServerResponseError.__name__ + t for t in _union_members(node.returns) if t != ServerResponseError.__name__ ].pop() return {