Refactor LabelledString and relevant classes

This commit is contained in:
YishiMichael
2022-04-18 18:47:57 +08:00
parent 0e0244128c
commit cbb7e69f68
6 changed files with 100 additions and 135 deletions

View File

@ -135,10 +135,14 @@ def make_even(
def hash_obj(obj: object) -> int:
if isinstance(obj, dict):
new_obj = {k: hash_obj(v) for k, v in obj.items()}
return hash(tuple(frozenset(sorted(new_obj.items()))))
return hash(tuple(sorted([
(hash_obj(k), hash_obj(v)) for k, v in obj.items()
])))
if isinstance(obj, (set, tuple, list)):
if isinstance(obj, set):
return hash(tuple(sorted(hash_obj(e) for e in obj)))
if isinstance(obj, (tuple, list)):
return hash(tuple(hash_obj(e) for e in obj))
if isinstance(obj, Color):