Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion autoconf/dictable.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ def to_dict(obj, filter_args: Tuple[str, ...] = ()) -> dict:
if isinstance(obj, tuple):
return {"type": "tuple", "values": list(map(to_dict, obj))}
if isinstance(obj, dict):
if any(isinstance(key, (list, dict, tuple)) for key in obj.keys()):
if any(
not (isinstance(key, (str, int, float, bool)) or key is None)
for key in obj.keys()
):
return compound_key_dict(obj)

return {
Expand Down
13 changes: 13 additions & 0 deletions test_autoconf/test_dictable.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,16 @@ def test_compound_key():

string = json.dumps(to_dict(d))
assert d == from_dict(json.loads(string))


class Prior:
def __eq__(self, other):
return isinstance(other, Prior)

def __hash__(self):
return hash(Prior)


def test_prior_key():
string = json.dumps(to_dict({Prior(): 1}))
assert from_dict(json.loads(string)) == {Prior(): 1}