def create_autospec(spec, spec_set=False, inherit=False, configure=None,
                    _parent=None, _name=None, _instance=False):
    """XXXX needs docstring!"""
    if configure is None:
        configure = {}

    if type(spec) == list:
        # can't pass a list instance to the mock constructor as it will be
        # interpreted as a list of strings
        spec = list

    is_type = isinstance(spec, ClassTypes)

    kwargs = {'spec': spec}
    if spec_set:
        kwargs = {'spec_set': spec}
    elif spec is None:
        # None we mock with a normal mock without a spec
        kwargs = {}

    kwargs.update(configure)
    mock = MagicMock(parent=_parent, name=_name, **kwargs)

    if isinstance(spec, FunctionTypes):
        # should only happen at the top level because we don't
        # recurse for functions
        mock = _set_signature(mock, spec, False)
    else:
        _check_signature(spec, mock, is_type)

    if _parent is not None:
        _parent._mock_children[_name] = mock

    if is_type and inherit and not _instance:
        # XXXX could give a name to the return_value mock?
        mock.return_value = create_autospec(spec, spec_set, inherit,
                                            _instance=True)

    for entry in dir(spec):
        if _is_magic(entry):
            continue

        if isinstance(spec, FunctionTypes) and FunctionAttributes in entry:
            # allow a mock to actually be a function from mocksignature
            continue

        # XXXX do we need a better way of getting attributes
        # without triggering code execution (?) Probably not - we need the
        # actual object to mock it so we would rather trigger a property than
        # mock the property descriptor. Likewise we want to mock out
        # dynamically provided attributes.
        original = getattr(spec, entry)

        kwargs = {'spec': original}
        if spec_set:
            kwargs = {'spec_set': original}

        if not isinstance(original, FunctionTypes):
            new = _SpecState(original, spec_set, inherit, mock, entry,
                               _instance)
            mock._mock_children[entry] = new
        else:
            parent = mock
            if isinstance(spec, FunctionTypes):
                parent = mock.mock

            new = MagicMock(parent=parent, name=entry, **kwargs)
            mock._mock_children[entry] = new
            skipfirst = _must_skip(spec, entry, is_type)
            _check_signature(original, new, skipfirst=skipfirst)

        # so functions created with mocksignature become instance methods,
        # *plus* their underlying mock exists in _mock_children of the parent
        # mock. Adding to _mock_children may be unnecessary where we are also
        # setting as an instance attribute?
        if isinstance(new, FunctionTypes):
            setattr(mock, entry, new)

    return mock
dataset/ETHPy150Open sibson/vncdotool/tests/unit/mock.py/create_autospec/swapped operands of `in`