from typing import Sequence
from typing import Union
from typing import Optional


def mean(values: Sequence[Union[int, float, None]]) -> Optional[float]:
    """
    Returns the mean of a list of numbers.

    Args:
        values: values to mean, ignoring any values that are ``None``

    Returns:
        the mean, or ``None`` if :math:`n = 0`

    """
    total = 0.0  # starting with "0.0" causes automatic conversion to float
    n = 0
    for x in values:
        if x is not None:
            total += x
            n += 1
    return total / n if n > 0 else None