def _get_origin(tp):
    """Return x.__origin__ or type(x) based on the Python version."""
    if hasattr(tp, '_gorg'):
        return tp._gorg
    if getattr(tp, '__origin__', None) is not None:
        return tp.__origin__
    return tp
