from typing import cast
from typing import Iterable
import itertools


def _test_for_equality_nestedly_and_block_implicit_bool_conversion(
    o1: object, o2: object
) -> bool:
    """test objects, or sequences, for equality. sequences are tested recursively.  Block
    implicit conversion of values to bools.

    >>> import methodfinder
    >>> methodfinder._test_for_equality_nestedly_and_block_implicit_bool_conversion(1,1)
    True
    >>> methodfinder._test_for_equality_nestedly_and_block_implicit_bool_conversion(1,2)
    False
    >>> methodfinder._test_for_equality_nestedly_and_block_implicit_bool_conversion([1,2,3],[1,2,3])
    True
    >>> methodfinder._test_for_equality_nestedly_and_block_implicit_bool_conversion([1,2,3],[2,1,3])
    False
    >>> methodfinder._test_for_equality_nestedly_and_block_implicit_bool_conversion(1,True)
    False"""
    try:
        # if they have iterators, no exception will be thrown

        # take 100 elements from them.  any user of methodfinder
        # will not be putting in more than 100 elements
        # if it's not an iterator, an exception will be thrown

        o1_iter = cast(Iterable[object], o1)
        o2_iter = cast(Iterable[object], o2)

        for e1, e2 in itertools.zip_longest(
            itertools.islice(o1_iter, 100), itertools.islice(o2_iter, 100)
        ):
            if not _test_for_equality_nestedly_and_block_implicit_bool_conversion(
                e1, e2
            ):
                return False
        return True
    except:
        # since at least one of the objects does not have an iterator,
        # just test for equality normally.
        # test that the types are the same to suppress implicit
        # conversion of values to bools, which returns
        # way too many useless results for the purpose of methodfinder
        return (type(o1) == type(o2)) and (o1 == o2)