Skip to content

get_object_state for objects with __getnewargs__ (or ..._ex__), state unnecessary #215

@albertz

Description

@albertz

In get_object_state, we already do this:

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

    ...

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

Why do we do this? The state is unnecessary when we have args, or not? When __getnewargs__ or __getnewargs_ex__ is implemented, this should cover the complete state of the object.

What cases do we currently have that actually use __getnewargs__/__getnewargs_ex__? I think this is quite rare, or maybe even non-existent?

Note, I currently have a case, where I implemented __getnewargs_ex__ for some own class, and I was confused that Sisyphus apparently anyway checks the other state.

I implemented __getnewargs_ex__ in a way that should be quite stable w.r.t. the hash, however, the internal object state might change in the future. So that is why I actually would want that Sisyphus only considers the __getnewargs_ex__ output when the object has this function.

The main question is if we have any hashes which would break now when we change this. The code in get_object_state would basically change to this:

    if hasattr(obj, "__getnewargs_ex__"):
        return obj.__getnewargs_ex__()
    elif hasattr(obj, "__getnewargs__"):
        return obj.__getnewargs__()

    ...

    return state

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions