from typing import Union
from typing import Optional


def _paging_int(value: Union[int, str]) -> Optional[int]:
    """Convert value to an int

    That value should already be an int
        but it can come from web-user, so may arrive here as a string
        or as nothing (NOne or empty string)

    >>> assert _paging_int(15) == 15
    >>> assert _paging_int("15") == 15
    >>> assert _paging_int("") == None
    >>> assert _paging_int(None) == None
    >>> try:
    ...     _paging_int("hello")
    ...     assert False, "Should raise an error"
    ... except:
    ...     pass
    """
    try:
        return int(value)
    except (TypeError, ValueError):
        if not value:
            return None
        raise