from typing import Union
import builtins
import importlib


def _load_exception_class(import_specifier: str) -> Union[Exception, None]:
    """Load an exception class to be used for filtering Sentry events.

    This function takes a string representation of an exception class to be filtered out
    of sending to Sentry and returns an uninitialized instance of the class so that it
    can be used as the argument to an `isinstance` method call.

    :param import_specifier: A string containing the full import path for an exception
        class.  ex.  'ValueError' or 'requests.exceptions.HTTPError'
    :type import_specifier: str

    :returns: An uninitialized reference to the exception type to be used in
              `isinstance` comparisons.

    :rtype: Exception
    """
    namespaced_class = import_specifier.rsplit(".", 1)
    if len(namespaced_class) == 1:
        return builtins.__dict__.get(namespaced_class[0])  # noqa: WPS609
    exception_module = importlib.import_module(namespaced_class[0])
    return exception_module.__dict__.get(namespaced_class[1])