Create an :class:`~.InvertableHashingVectorizer` from hashing
    vectorizer vec and fit it on docs. If vec is a FeatureUnion, do it for all
    hashing vectorizers in the union.
    Return an :class:`~.InvertableHashingVectorizer`, or a FeatureUnion,
    or an unchanged vectorizer.

def invert_hashing_and_fit(
        vec,  # type: Union[FeatureUnion, HashingVectorizer]
        docs
    ):
    # type: (...) -> Union[FeatureUnion, InvertableHashingVectorizer]
    """ Create an :class:`~.InvertableHashingVectorizer` from hashing
    vectorizer vec and fit it on docs. If vec is a FeatureUnion, do it for all
    hashing vectorizers in the union.
    Return an :class:`~.InvertableHashingVectorizer`, or a FeatureUnion,
    or an unchanged vectorizer.
    """
    if isinstance(vec, HashingVectorizer):
        vec = InvertableHashingVectorizer(vec)
        vec.fit(docs)
    elif (isinstance(vec, FeatureUnion) and
              any(isinstance(v, HashingVectorizer)
                  for _, v in vec.transformer_list)):
        vec = _fit_invhashing_union(vec, docs)
    return vec