Skip to content

Commit

Permalink
Fix using sets with V2 Struct causing unhashable TypeError (pantsbu…
Browse files Browse the repository at this point in the history
…ild#7747)

### Problem
When running our whole unit test suite with V2, we encounter a `TypeError` that sets are not hashable. This happens because one of the tests includes the value `'tags': {'platform_specific_behavior'}`, which gets stored in its `Struct`.

### Solution
Teach `Struct` how to safely hash `set`. We must first sort the `set` because `set`s have non-deterministic ordering.
  • Loading branch information
Eric-Arellano authored and stuhood committed May 17, 2019
1 parent fdf204e commit 7e5d82b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/python/pants/engine/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def hashable(value):
return tuple(sorted((k, hashable(v)) for k, v in value.items()))
elif isinstance(value, list):
return tuple(hashable(v) for v in value)
elif isinstance(value, set):
return tuple(sorted(hashable(v) for v in value))
else:
return value
return tuple(sorted((k, hashable(v)) for k, v in self._kwargs.items()
Expand Down

0 comments on commit 7e5d82b

Please sign in to comment.