def data2schema(
        _data=None, _force=False, _besteffort=True, _registry=None,
        _factory=None, _buildkwargs=None, **kwargs
):
    """Get the schema able to instanciate input data.

    The default value of schema will be data.

    Can be used such as a decorator:

    ..code-block:: python

        @data2schema
        def example(): pass  # return a function schema

        @data2schema(_registry=myregistry)
        def example(): pass  # return a function schema with specific registry

    ..warning::

        return this function id _data is None.

    :param _data: data possibly generated by a schema. Required but in case of
        decorator.
    :param bool _force: if True (False by default), create the data schema
        on the fly if it does not exist.
    :param bool _besteffort: if True (default), find a schema class able to
        validate data class by inheritance.
    :param SchemaRegistry _registry: default registry to use. Global by
        default.
    :param SchemaFactory factory: default factory to use. Global by default.
    :param dict _buildkwargs: factory builder kwargs.
    :param kwargs: schema class kwargs.
    :return: Schema.
    :rtype: Schema.
    """
    if _data is None:
        return lambda _data: data2schema(
            _data, _force=False, _besteffort=True, _registry=None,
            _factory=None, _buildkwargs=None, **kwargs
        )

    result = None

    fdata = _data() if isinstance(_data, DynamicValue) else _data

    datatype = type(fdata)

    content = getattr(fdata, '__dict__', {})
    if _buildkwargs:
        content.udpate(_buildkwargs)

    schemacls = datatype2schemacls(
        _datatype=datatype, _registry=_registry, _factory=_factory,
        _force=_force, _besteffort=_besteffort, **content
    )

    if schemacls is not None:
        result = schemacls(default=_data, **kwargs)

        for attrname in dir(_data):

            if not hasattr(schemacls, attrname):
                attr = getattr(_data, attrname)
                if attr is not None:
                    setattr(result, attrname, attr)

    if result is None and _data is None:
        result = AnySchema()

    return result
Get the schema able to instanciate input data.

    The default value of schema will be data.

    Can be used such as a decorator:

    ..code-block:: python

        @data2schema
        def example(): pass  # return a function schema

        @data2schema(_registry=myregistry)
        def example(): pass  # return a function schema with specific registry

    ..warning::

        return this function id _data is None.

    :param _data: data possibly generated by a schema. Required but in case of
        decorator.
    :param bool _force: if True (False by default), create the data schema
        on the fly if it does not exist.
    :param bool _besteffort: if True (default), find a schema class able to
        validate data class by inheritance.
    :param SchemaRegistry _registry: default registry to use. Global by
        default.
    :param SchemaFactory factory: default factory to use. Global by default.
    :param dict _buildkwargs: factory builder kwargs.
    :param kwargs: schema class kwargs.
    :return: Schema.
    :rtype: Schema.