import warnings
from typing import Optional
from typing import Union
from typing import Type
from typing import cast


def _is_unexpected_warning(
    actual_warning: warnings.WarningMessage,
    expected_warning: Optional[Union[Type[Warning], bool]],
) -> bool:
    """Check if the actual warning issued is unexpected."""
    if actual_warning and not expected_warning:
        return True
    expected_warning = cast(Type[Warning], expected_warning)
    return bool(not issubclass(actual_warning.category, expected_warning))