from typing import Any
from typing import Sequence


def indexof(needle: Any, haystack: Sequence[Any]) -> int:
    """Gets the index of some item in a sequence.

    Find an index of ``needle`` in ``haystack`` by looking for exact same
    item by pointer ids vs usual ``list.index()`` which finds
    by object comparison.

    Args:
        needle: The object or item to find in the sequence.
        haystack: The sequence of items to search for the ``needle``.

    Returns:
        The index of the needle in the haystack.

    Raises:
        ValueError: If the needle is not found inside the haystack.

    For example::

        >>> a = {}
        >>> b = {}
        >>> haystack = [1, a, 2, b]
        >>> indexof(b, haystack)
        3
        >>> indexof(None, haystack)
        Traceback (most recent call last):
        ...
        ValueError: None is not in [1, {}, 2, {}]
    """
    for i, item in enumerate(haystack):
        if needle is item:
            return i
    raise ValueError("{!r} is not in {!r}".format(needle, haystack))