From dc4d51599e32e610ba34626abc432f71667622dc Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Tue, 16 Jul 2024 14:58:13 +0200 Subject: [PATCH] feat: get all url sources --- src/rattler_build_conda_compat/conditional_list.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/rattler_build_conda_compat/conditional_list.py b/src/rattler_build_conda_compat/conditional_list.py index 945b580..0683aa4 100644 --- a/src/rattler_build_conda_compat/conditional_list.py +++ b/src/rattler_build_conda_compat/conditional_list.py @@ -1,10 +1,8 @@ from __future__ import annotations -from typing import Any, Callable, Generator, Generic, TypeVar, Union +from typing import Any, Callable, Generator, Generic, TypeVar, Union, List, cast T = TypeVar("T") - - class IfStatement(Generic[T]): if_: Any then: T | list[T] @@ -36,23 +34,29 @@ def yield_from_list(value: list[T] | T) -> Generator[T, None, None]: else: yield value - value = value if isinstance(value, list) else [value] + if not isinstance(value, list): + value = [value] for element in value: if isinstance(element, dict): if (expr := element.get("if", None)) is not None: then = element.get("then") otherwise = element.get("else") + # Evaluate the if expression if the evaluator is provided if evaluator: if evaluator(expr): yield from yield_from_list(then) elif otherwise: yield from yield_from_list(otherwise) + # Otherwise, just yield the branches else: yield from yield_from_list(then) if otherwise: yield from yield_from_list(otherwise) else: + # In this case its not an if statement yield element + # If the element is not a dictionary, just yield it else: + # (tim) I get a pyright error here, but I don't know how to fix it yield element