from typing import Any
import importlib


def import_object(import_path: str) -> Any:
    """Imports an object from a given import path"""
    if "." not in import_path:
        raise ValueError(f"Import path {import_path} doesn't reference an object in a module.")
    module_name, object_name = import_path.rsplit(".", 1)

    try:
        module = importlib.import_module(module_name)
    except ModuleNotFoundError as exception:
        raise ModuleNotFoundError(f"{exception}. Given import path '{import_path}' is invalid.") from exception

    if hasattr(module, object_name):
        return getattr(module, object_name)

    raise ImportError(
        f"Cannot import name '{object_name}' from {module_name} ({module.__file__}). Given import path "
        f"'{import_path}' is invalid."
    )