from typing import Any


def check_type(o: Any, target_type: str) -> bool:
    """
    Check if `o`'s class path + name matches `target_type`.

    E.g. `check_type(o, "numpy.ndarray")`

    Checking types using this method instead of `isinstance` with the actual type is
    preferred here so that we don't have to import pytorch, PIL, and numpy (and complicate
    the code by handling import errors if any of these are missing, importing comet-ml
    before pytorch, etc.).
    """
    return str(type(o)) == f"<class '{target_type}'>"