Skip to content

Commit

Permalink
make collections work with unhashable objects
Browse files Browse the repository at this point in the history
  • Loading branch information
cjw296 committed Jan 31, 2019
1 parent 7fbfa10 commit 13b7656
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chide/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def __init__(self, mapping):
def _attrs(self, type_, attrs, nest):
computed_attrs = dict(self.mapping[type_])
for key, value in computed_attrs.items():
if value in self.mapping and key not in attrs:
try:
value_in_mapping = value in self.mapping
except TypeError:
value_in_mapping = False
if value_in_mapping and key not in attrs:
computed_attrs[key] = nest(value)
computed_attrs.update(attrs)
return computed_attrs
Expand Down
6 changes: 6 additions & 0 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ def identify_type_c(type_, attrs):
compare(sample1.key, expected=1)
self.assertTrue(sample1 is sample2)

def test_unhashable_attributes(self):
unhashable = []
collection = Collection({dict: {'y': unhashable}})
made = collection.make(dict)
compare(made, expected={'y': []})
assert made['y'] is unhashable

0 comments on commit 13b7656

Please sign in to comment.