Message269370
When trying to see if the keys() of a collections.ChainMap object are empty, it tries to compute the hash of the dicts that compose the ChainMap, giving rise to an error:
In [1]: from collections import ChainMap
In [2]: m = ChainMap([{'a':1}, {'b':2}])
In [3]: bool(m.keys())
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-365f7b817ebf> in <module>()
----> 1 bool(m.keys())
/home/zah/anaconda3/lib/python3.5/_collections_abc.py in __len__(self)
633
634 def __len__(self):
--> 635 return len(self._mapping)
636
637 def __repr__(self):
/home/zah/anaconda3/lib/python3.5/collections/__init__.py in __len__(self)
865
866 def __len__(self):
--> 867 return len(set().union(*self.maps)) # reuses stored hash values if possible
868
869 def __iter__(self):
TypeError: unhashable type: 'dict'
Also, I can't ask if 'a' is in keys:
In [6]: m.keys()
Out[6]: KeysView(ChainMap([{'a': 1}, {'b': 2}]))
In [9]: ks = m.keys()
In [17]: 'a' in ks
Out[17]: False |
|
Date |
User |
Action |
Args |
2016-06-27 11:07:45 | Zahari.Dim | set | recipients:
+ Zahari.Dim |
2016-06-27 11:07:45 | Zahari.Dim | set | messageid: <1467025665.28.0.0299580646489.issue27399@psf.upfronthosting.co.za> |
2016-06-27 11:07:45 | Zahari.Dim | link | issue27399 messages |
2016-06-27 11:07:44 | Zahari.Dim | create | |
|