Skip to content

Commit

Permalink
get_object_state, use args only when available
Browse files Browse the repository at this point in the history
Fix #215
  • Loading branch information
albertz committed Nov 5, 2024
1 parent 3181d72 commit aad7ccd
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions sisyphus/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ def get_object_state(obj):
return str(obj)

if hasattr(obj, "__getnewargs_ex__"):
args = obj.__getnewargs_ex__()
return obj.__getnewargs_ex__()
elif hasattr(obj, "__getnewargs__"):
args = obj.__getnewargs__()
else:
args = None
return obj.__getnewargs__()

if hasattr(obj, "__sis_state__"):
state = obj.__sis_state__()
Expand All @@ -102,18 +100,14 @@ def get_object_state(obj):
state = _getmembers(obj)
if not state and not hasattr(obj, "__dict__") and not hasattr(obj, "__slots__"):
# Keep compatibility with old behavior.
assert args is not None, "Failed to get object state of: %s" % repr(obj)
state = None
raise ValueError("Failed to get object state of: %s" % repr(obj))

if isinstance(obj, enum.Enum):
assert isinstance(state, dict)
# In Python >=3.11, keep hash same as in Python <=3.10, https://github.com/rwth-i6/sisyphus/issues/188
state.pop("_sort_order_", None)

if args is None:
return state
else:
return args, state
return state


def sis_hash_helper(obj):
Expand Down

0 comments on commit aad7ccd

Please sign in to comment.