projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix a recent bug in executors. Thread executor needs to return
[python_utils.git]
/
collect
/
bidict.py
diff --git
a/collect/bidict.py
b/collect/bidict.py
index e16217994334a6af750cea13bd88a03f309b2329..8153e54446c8a4c5a36f96ba85e0b93c9afafe18 100644
(file)
--- a/
collect/bidict.py
+++ b/
collect/bidict.py
@@
-1,6
+1,6
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
-class
bid
ict(dict):
+class
BiD
ict(dict):
def __init__(self, *args, **kwargs):
"""
A class that stores both a Mapping between keys and values and
def __init__(self, *args, **kwargs):
"""
A class that stores both a Mapping between keys and values and
@@
-9,7
+9,7
@@
class bidict(dict):
is possible to have several keys with the same value, using
the inverse map returns a sequence of keys.
is possible to have several keys with the same value, using
the inverse map returns a sequence of keys.
- >>> d =
bid
ict()
+ >>> d =
BiD
ict()
>>> d['a'] = 1
>>> d['b'] = 2
>>> d['c'] = 2
>>> d['a'] = 1
>>> d['b'] = 2
>>> d['c'] = 2
@@
-35,14
+35,16
@@
class bidict(dict):
def __setitem__(self, key, value):
if key in self:
def __setitem__(self, key, value):
if key in self:
- self.inverse[self[key]].remove(key)
+ old_value = self[key]
+ self.inverse[old_value].remove(key)
super().__setitem__(key, value)
self.inverse.setdefault(value, []).append(key)
def __delitem__(self, key):
super().__setitem__(key, value)
self.inverse.setdefault(value, []).append(key)
def __delitem__(self, key):
- self.inverse.setdefault(self[key], []).remove(key)
- if self[key] in self.inverse and not self.inverse[self[key]]:
- del self.inverse[self[key]]
+ value = self[key]
+ self.inverse.setdefault(value, []).remove(key)
+ if value in self.inverse and not self.inverse[value]:
+ del self.inverse[value]
super().__delitem__(key)
super().__delitem__(key)