Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChainMap.keys() is broken #71586

Closed
Zaharid mannequin opened this issue Jun 27, 2016 · 1 comment
Closed

ChainMap.keys() is broken #71586

Zaharid mannequin opened this issue Jun 27, 2016 · 1 comment
Labels
stdlib Python modules in the Lib dir

Comments

@Zaharid
Copy link
Mannequin

Zaharid mannequin commented Jun 27, 2016

BPO 27399
Nosy @rhettinger, @Zaharid

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-06-27.11:13:00.243>
created_at = <Date 2016-06-27.11:07:45.246>
labels = ['invalid', 'library']
title = 'ChainMap.keys() is broken'
updated_at = <Date 2016-06-27.13:30:35.459>
user = 'https://github.com/Zaharid'

bugs.python.org fields:

activity = <Date 2016-06-27.13:30:35.459>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2016-06-27.11:13:00.243>
closer = 'Zahari.Dim'
components = ['Library (Lib)']
creation = <Date 2016-06-27.11:07:45.246>
creator = 'Zahari.Dim'
dependencies = []
files = []
hgrepos = []
issue_num = 27399
keywords = []
message_count = 1.0
messages = ['269370']
nosy_count = 2.0
nosy_names = ['rhettinger', 'Zahari.Dim']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue27399'
versions = ['Python 3.5']

@Zaharid
Copy link
Mannequin Author

Zaharid mannequin commented Jun 27, 2016

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

@Zaharid Zaharid mannequin added the stdlib Python modules in the Lib dir label Jun 27, 2016
@Zaharid Zaharid mannequin closed this as completed Jun 27, 2016
@Zaharid Zaharid mannequin added the invalid label Jun 27, 2016
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

0 participants