def is_qfunction(obj, qtype=None):
    """

    Check whether an object is a :term:`state-action value function <type-I
    state-action value function>`, or Q-function.

    Parameters
    ----------
    obj

        Object to check.

    qtype : 1 or 2, optional

        Check for specific Q-function type, i.e. :term:`type-I <type-I
        state-action value function>` or :term:`type-II <type-II state-action
        value function>`.

    Returns
    -------
    bool

        Whether ``obj`` is a (type-I/II) Q-function.

    """
    from ..core.value_q import QTypeI, QTypeII
    if qtype is None:
        return isinstance(obj, (QTypeI, QTypeII))
    elif qtype in (1, 1.0, '1', 'i', 'I'):
        return isinstance(obj, QTypeI)
    elif qtype in (2, 2.0, '2', 'ii', 'II'):
        return isinstance(obj, QTypeII)
    else:
        raise ValueError('unexpected qtype: {}'.format(qtype))
