from typing import get_origin
from typing import Sequence


def _is_collection_type(o) -> bool:
    """
    Check whether the provided type/annotation is one which can hold elements. Necessarily since the minor versions
    of Python 3 have evolving ways of comparing type annotations.

    :param o: An annotation or type reference
    :return: Whether it represents a type which can hold elements
    """
    try:
        # Py3.9+
        cls = get_origin(o) or o
        return issubclass(cls, Sequence)
    except ImportError:
        pass

    # extract the base type if 'o' is an annotation
    cls = o if type(o) == type else o.__orig_bases__[0]
    return issubclass(cls, Sequence)