Takes in a list of short forms of assumptions and an assumption
dictionary, and returns a "list" form of the long form of the
assumptions.

Raises
------
ValueError
    if one of the assumptions is not in assumption_dict.
486398
def assumption_list_string(assumptions, assumption_dict):
    '''

    '''
    if isinstance(assumptions, six.string_types):
        raise TypeError('assumptions must be an iterable of strings, not a '
                        'string itself')
    for a in assumptions:
        if a not in assumption_dict.keys():
            raise ValueError('{} not present in assumption_dict'.format(a))
    assumption_strings = [assumption_dict[a] for a in assumptions]
    return strings_to_list_string(assumption_strings)
569101
def takes(*type_list):
    
    def inner(f):
        if enabled:
            # deal with the real function, not a wrapper
            f = getattr(f, 'wrapped_fn', f)

            # need to check if 'self' is the first arg,
            # since @pre doesn't want the self param
            member_function = is_member_function(f)

            # need metadata for defaults check
            method_args, method_defaults = inspect.getargspec(f)[0::3]
            if member_function:
                method_args = method_args[member_function:]

            def check_condition(args, kwargs):
                if method_defaults is not None and len(method_defaults) > 0 \
                and len(method_args) - len(method_defaults) <= len(args) < len(method_args):
                    args += method_defaults[len(args) - len(method_args):]

                for i, (arg, t) in enumerate(zip(args[member_function:], type_list)):
                    method_arg = method_args[i]
                    if method_arg not in kwargs and not check_type(t, arg):
                        raise AssertionError('Precondition failure, wrong type for argument')

                for kwarg in kwargs:
                    arg_position = method_args.index(kwarg)
                    if arg_position < len(type_list):
                        t = type_list[arg_position]
                        if not check_type(t, kwargs.get(kwarg)):
                            raise AssertionError('Precondition failure, wrong type for argument %s' % kwarg)

            # append to the rest of the postconditions attached to this method
            if not hasattr(f, 'preconditions'):
                f.preconditions = []
            f.preconditions.append(check_condition)

            return check(f)
        else:
            return f

    return inner
442983
def parse(constraints):
    
    if not constraints:
        return None

    if type(constraints) is dict:
        # Fowards compatibilty: already parsed
        return constraints

    constraints = {
        normalize_key(k): (
            normalize_list_value(v) if k in LIST_KEYS else
            normalize_value(v)
        ) for k, v in [s.split("=") for s in constraints.split(" ")]}

    return constraints
1101281
def coerce_to_list(items, preprocess=None):
    
    if not isinstance(items, list):
        items = [items]
    if preprocess:
        items = list(map(preprocess, items))
    return items
255804
def fmt_dict_vals(dict_vals, shorten=True):
    
    items = dict_vals.items()
    if not items:
        return [fmt_val(None, shorten=shorten)]
    return ["%s=%s" % (k, fmt_val(v, shorten=shorten)) for k,v in items]
1263515
def flat_list(lst):
    
    if isinstance(lst, list):
        for item in lst:
            for i in flat_list(item):
                yield i
    else:
        yield lst
565211
def as_list(self, decode=False):
        
        return [_decode(i) for i in self] if decode else list(self)
1129277
def inverted_dict_of_lists(d):
    
    new_dict = {}
    for (old_key, old_value_list) in viewitems(dict(d)):
        for new_key in listify(old_value_list):
            new_dict[new_key] = old_key
    return new_dict
200923
def flatten_list(l: List[list]) -> list:
    
    return [v for inner_l in l for v in inner_l]
611661
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'models' in _dict:
            args['models'] = [
                Model._from_dict(x) for x in (_dict.get('models'))
            ]
        return cls(**args)
1143835
def dict_merge(*dict_list):
    
    result = collections.defaultdict(dict)
    dicts_items = itertools.chain(*[six.iteritems(d or {}) for d in dict_list])

    for key, value in dicts_items:
        src = result[key]
        if isinstance(src, dict) and isinstance(value, dict):
            result[key] = dict_merge(src, value)
        elif isinstance(src, dict) or isinstance(src, six.text_type):
            result[key] = value
        elif hasattr(src, "__iter__") and hasattr(value, "__iter__"):
            result[key] += value
        else:
            result[key] = value

    return dict(result)
1269564
def scrub_dict(d):
    
    if type(d) is dict:
        return dict(
            (k, scrub_dict(v)) for k, v in d.iteritems() if v and scrub_dict(v)
        )
    elif type(d) is list:
        return [
            scrub_dict(v) for v in d if v and scrub_dict(v)
        ]
    else:
        return d
1308216
def _to_list(var):
    
    if isinstance(var, list):
        return var
    elif var is None:
        return []
    elif isinstance(var, str) or isinstance(var, dict):
        # We dont want to make a list out of those via the default constructor
        return [var]
    else:
        try:
            return list(var)
        except TypeError:
            return [var]
332398
def to_python(self, value):
        
        if not value:
            value = []

        # If a list is set then validated its items
        if isinstance(value, list):
            py_list = self.validate_list(value)
        else:  # try to de-serialize value and expect list and then validate
            try:
                py_list = json.loads(value)

                if not isinstance(py_list, list):
                    raise TypeError

                self.validate_list(py_list)
            except (ValueError, TypeError):
                raise ValidationError(u'Must be a valid list of strings.')

        return py_list
1235582
def check_validity_of_long_form_args(model_obj, wide_weights, rows_to_obs):
    
    # Ensure model_obj has the necessary method for create_long_form_weights
    ensure_model_obj_has_mapping_constructor(model_obj)
    # Ensure wide_weights is a 1D or 2D ndarray.
    ensure_wide_weights_is_1D_or_2D_ndarray(wide_weights)
    # Ensure rows_to_obs is a scipy sparse matrix
    ensure_rows_to_obs_validity(rows_to_obs)
    return None
1141117
def dict_values(src):
    
    for v in src.values():
        if isinstance(v, dict):
            for v in dict_values(v):
                yield v
        else:
            yield v
198316
def _flatten_dicts(self, dicts):
        
        d = dict()
        list_of_dicts = [d.get() for d in dicts or []]
        return {k: v for d in list_of_dicts for k, v in d.items()}