from typing import Iterable


def attributes2docval(attributes, prefix):
    """
    Takes a spec attribute and creates the appropriate docval entry
    Parameters
    ----------
    attributes: dict
    prefix: str

    Returns
    -------
    tuple: docval entry

    """
    args_spec = []

    for attrib in attributes:
        if 'shape' in attrib:
            _type = Iterable
        elif attrib.dtype == 'text':
            _type = str
        else:
            _type = attrib.dtype

        arg_spec = {'name': prefix + attrib.name,
                    'type': _type,
                    'doc': attrib.doc}
        if 'value' in attrib:
            arg_spec['default'] = attrib.value
        elif not attrib.required:
            arg_spec['default'] = None
        if 'shape' in attrib:
            arg_spec['shape'] = attrib.shape
        if not attrib.name == 'help':
            args_spec.append(arg_spec)

    return args_spec