# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/01t_utils.misc.ipynb.

# %% auto 0
__all__ = ['kwargs_grid', 'safe_zip', 'skip_error']

# %% ../../nbs/01t_utils.misc.ipynb 2
from fastcore.all import *
import numbers
import polvo as pv

from PIL import Image

# %% ../../nbs/01t_utils.misc.ipynb 3
def kwargs_grid(**kwargs):
    "Returns a generator with all combinations of kwargs"
    return (dict(zip(kwargs.keys(), v)) for v in itertools.product(*kwargs.values()))

# %% ../../nbs/01t_utils.misc.ipynb 5
@functools.wraps(zip)
def safe_zip(*args, **kwargs):
    if len(set(map(len, args))) not in (0, 1):
        raise ValueError(f'All elements should have the same size, but got {[len(x) for x in args]}')
    return zip(*args, **kwargs)

# %% ../../nbs/01t_utils.misc.ipynb 8
class skip_error:
    def __init__(self, fn, log=True):
        'Returns the error instead of raising it.'
        store_attr()
        
    def __call__(self, *args, **kwargs):
        try: return self.fn(*args, **kwargs)
        except Exception as e: 
            if self.log: print((args, kwargs))
            return e
