summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitali Lovich <vlovich+github@gmail.com>2018-06-13 12:06:46 -0700
committerGitHub <noreply@github.com>2018-06-13 12:06:46 -0700
commit791fa852a6ae28be43f6211d6ce226a691c37773 (patch)
tree46c17f15497bd5fd5f915fec1b7a33dae7e7e50d
parent22d3900706df7a9c3846094f04dde830553e1a7c (diff)
downloadpyserial-git-791fa852a6ae28be43f6211d6ce226a691c37773.tar.gz
Make ListPortInfo hashable
Makes it behave as consistently within unordered data structures like sets/hashes.
-rw-r--r--serial/tools/list_ports_common.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/serial/tools/list_ports_common.py b/serial/tools/list_ports_common.py
index 8a1b625..617f3dc 100644
--- a/serial/tools/list_ports_common.py
+++ b/serial/tools/list_ports_common.py
@@ -77,6 +77,9 @@ class ListPortInfo(object):
def __eq__(self, other):
return isinstance(other, ListPortInfo) and self.device == other.device
+ def __hash__(self):
+ return hash(self.device)
+
def __lt__(self, other):
if not isinstance(other, ListPortInfo):
raise TypeError('unorderable types: {}() and {}()'.format(