Skip to content


Source code in treeo/
class Opaque(tp.Generic[A]):
    def __init__(self, value: A, predicate: tp.Optional[OpaquePredicate]):
        self.value = value
        self.predicate = predicate

    def __repr__(self):
        return f"Hidden({self.value})"

    def __eq__(self, other):
        if self.predicate is not None:
            return self.predicate(self, other)
            # if both are Opaque and their values are of the same type
            if isinstance(other, Opaque) and type(self.value) == type(other.value):
                # if they are array-like also compare their shapes and dtypes
                if isinstance(self.value, ArrayLike):
                    other_value = tp.cast(ArrayLike, other.value)
                    return (
                        self.value.shape == other_value.shape
                        and self.value.dtype == other_value.dtype
                    # else they are equal
                    return True
                return False