Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils: Add a flatten function to Utils.py #3167

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import json
import types
import typing
import builtins
import os
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Loading