from typing import Type
from typing import get_origin
from typing import get_args
from typing import Union


def _get_field_origin(field_type: Type) -> Type:
    """ Helper to extract generic origin """

    origin = get_origin(field_type)
    args = get_args(field_type)
    if origin is Union and args[-1] is type(None):  # noqa: E721
        return args[0]
    else:
        return field_type