def METHOD_NAME(x):
    """Extract the function space from a Firedrake object `x`.
    Parameters
    ----------
    x : float, firedrake.function.Function or firedrake.vector.Vector
        Firedrake object from which to extract the function space.
    Returns
    -------
    firedrake.functionspaceimpl.WithGeometry or None
        Extracted function space.
    """
    if isinstance(x, Function):
        return x.function_space()
    elif isinstance(x, Vector):
        return METHOD_NAME(x.function)
    elif isinstance(x, float):
        return None
    else:
        raise ValueError("Cannot infer the function space of %s" % x)