Skip to content

Commit

Permalink
Add some types to equals_tester.py (quantumlib#5053)
Browse files Browse the repository at this point in the history
Adds more type hints to `equal_tester.py`
  • Loading branch information
vtomole authored Mar 3, 2022
1 parent 2dbba7a commit 53c0cd8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cirq/testing/equals_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@

import collections

from typing import Any, Callable
from typing import Any, Callable, List, Tuple, Union

import itertools


class EqualsTester:
"""Tests equality against user-provided disjoint equivalence groups."""

def __init__(self):
self._groups = [(_ClassUnknownToSubjects(),)]
def __init__(self) -> None:
self._groups: List[Tuple[Union[Any, _ClassUnknownToSubjects], ...]] = [
(_ClassUnknownToSubjects(),)
]

def _verify_equality_group(self, *group_items: Any):
"""Verifies that a group is an equivalence group.
Expand Down Expand Up @@ -134,10 +136,10 @@ def make_equality_group(self, *factories: Callable[[], Any]):
class _ClassUnknownToSubjects:
"""Equality methods should be able to deal with the unexpected."""

def __eq__(self, other):
def __eq__(self, other: object) -> bool:
return isinstance(other, _ClassUnknownToSubjects)

def __ne__(self, other):
def __ne__(self, other: object) -> bool:
return not self == other

def __hash__(self):
Expand All @@ -150,10 +152,10 @@ class _TestsForNotImplemented:
This class is equal to a specific instance or delegates by returning NotImplemented.
"""

def __init__(self, other):
def __init__(self, other: object) -> None:
self.other = other

def __eq__(self, other):
def __eq__(self, other: object) -> bool:
return True if other is self.other else NotImplemented


Expand Down

0 comments on commit 53c0cd8

Please sign in to comment.