Skip to content

Commit

Permalink
Fix: hardware.setup._SingleChannel.__eq__
Browse files Browse the repository at this point in the history
__eq__ function does not use __hash__ anymore. Instead it uses the tuple used in __hash__ directly.
  • Loading branch information
lumip committed Apr 23, 2018
1 parent 140a355 commit e5471b0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions qctoolkit/hardware/setup.py
@@ -1,4 +1,4 @@
from typing import NamedTuple, Set, Callable, Dict, Tuple, Union, Iterable
from typing import NamedTuple, Set, Callable, Dict, Tuple, Union, Iterable, Any
from collections import defaultdict, deque
import warnings

Expand Down Expand Up @@ -33,11 +33,16 @@ def __init__(self, awg: AWG, channel_on_awg: int):
self.channel_on_awg = channel_on_awg
"""The channel's index(starting with 0) on the AWG."""

@property
def compare_key(self) -> Tuple[Any]:
return (id(self.awg), self.channel_on_awg, type(self))

def __hash__(self):
return hash((id(self.awg), self.channel_on_awg, type(self)))
return hash(self.compare_key)

def __eq__(self, other):
return hash(self) == hash(other)
if not isinstance(other, _SingleChannel): return False
return self.compare_key == other.compare_key


class PlaybackChannel(_SingleChannel):
Expand Down

0 comments on commit e5471b0

Please sign in to comment.