diff --git a/Utils.py b/Utils.py index 6d4462651c89..2cb046b36014 100644 --- a/Utils.py +++ b/Utils.py @@ -2,6 +2,7 @@ import asyncio import json +import types import typing import builtins import os @@ -18,7 +19,7 @@ from argparse import Namespace from settings import Settings, get_settings -from typing import BinaryIO, Coroutine, Optional, Set, Dict, Any, Union +from typing import BinaryIO, Coroutine, Generator, List, Optional, Set, TypeVar, Dict, Any, Union from typing_extensions import TypeGuard from yaml import load, load_all, dump @@ -775,6 +776,14 @@ def async_start(co: Coroutine[None, None, typing.Any], name: Optional[str] = Non task.add_done_callback(_faf_tasks.discard) +T = TypeVar("T") +def flatten(l: List[T] | Generator[T] | T) -> List[T]: + if type(l) is list or type(l) is types.GeneratorType: + return [ y for x in l for y in flatten(x) ] + else: + return [ l ] + + def deprecate(message: str): if __debug__: raise Exception(message)