cirq.value_equality(cls: type = None, *, unhashable: bool = False, distinct_child_types: bool = False) → Union[Callable[type, type], type][source]

Implements eq/ne/hash via a value_equality_values method.

value_equality_values is a method that the decorated class must implement.

Note that the type of the decorated value is included as part of the value
equality values. This is so that completely separate classes with identical
equality values (e.g. a Point2D and a Vector2D) don’t compare as equal.
Further note that this means that child types of the decorated type will be
considered equal to each other, though this behavior can be changed via
the ‘distinct_child_types``argument. The type logic is implemented behind the scenes by a``value_equality_values_cls` method added to the class.
  • cls – The type to decorate. Automatically passed in by python when using the @cirq.value_equality decorator notation on a class.
  • unhashable – When set, the __hash__ method will be set to None instead of to a hash of the equality class and equality values. Useful for mutable types such as dictionaries.
  • distinct_child_types – When set, classes that inherit from the decorated class will not be considered equal to it. Also, different child classes will not be considered equal to each other. Useful for when the decorated class is an abstract class or trait that is helping to define equality for many conceptually distinct concrete classes.