<gh_stars>10-100
# Author: <NAME> at 19/06/2021 <<EMAIL>>
# Licence: MIT License
# Copyright: <NAME> (2018) <<EMAIL>>
from collections import defaultdict
from inspect import signature
from typing import Iterable

from tqdm import tqdm

VERBOSITY = 1


def verbosity(level=None):
    global VERBOSITY
    if isinstance(level, int) and VERBOSITY != level:
        VERBOSITY = level
    return VERBOSITY


def progress(it, *args, **kwargs):
    if VERBOSITY > 0:
        return tqdm(it, *args, **kwargs)
    else:
        return it


def safe_defaultdict_copy(d):
    new_d = defaultdict(list)
    for key, item in d.items():
        if isinstance(item, Iterable):
            new_d[key] = list(item)
        else:
            new_d[key] += [item]
    return new_d


def _obj_from_kwargs(klas, kwargs):
    sig = signature(klas.__init__)
    params = list(sig.parameters.keys())
    klas_kwargs = {n: v for n, v in kwargs.items() if n in params}
    return klas(**klas_kwargs)

# Author: <NAME> at 19/06/2021 <<EMAIL>>
# Licence: MIT License
# Copyright: <NAME> (2018) <<EMAIL>>
from collections import defaultdict
from inspect import signature
from typing import Iterable

from tqdm import tqdm

VERBOSITY = 1


def verbosity(level=None):
    global VERBOSITY
    if isinstance(level, int) and VERBOSITY != level:
        VERBOSITY = level
    return VERBOSITY


def progress(it, *args, **kwargs):
    if VERBOSITY > 0:
        return tqdm(it, *args, **kwargs)
    else:
        return it


def safe_defaultdict_copy(d):
    new_d = defaultdict(list)
    for key, item in d.items():
        if isinstance(item, Iterable):
            new_d[key] = list(item)
        else:
            new_d[key] += [item]
    return new_d


def _obj_from_kwargs(klas, kwargs):
    sig = signature(klas.__init__)
    params = list(sig.parameters.keys())
    klas_kwargs = {n: v for n, v in kwargs.items() if n in params}
    return klas(**klas_kwargs)
# Author: <NAME> at 19/06/2021 <<EMAIL>> # Licence: MIT License # Copyright: <NAME> (2018) <<EMAIL>>