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
2 changes: 2 additions & 0 deletions lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@
"pty",
"numpy.lib.npyio.loadtxt",
"pycrypto",
"pydoc.locate",
"pydoc.pipepager",
"pydoc.replace",
"pandas.read_pickle",
"python",
"pywin32_system32",
Expand Down
40 changes: 28 additions & 12 deletions third_party/corrupy/picklemagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,29 +841,45 @@ def load_build(self, *unused_args):
return

try:
inst.__setstate__(state)
except AttributeError:
setstate = getattr(inst, "__setstate__", None)
if setstate is not None:
setstate(state)
return

logger.warning(
"Attribute __setstate__ is not available for object %s", type(inst)
)
# Standard pickle fallback: if __setstate__ is not defined,
# update __dict__ or slots.
dict_state = state
slots_state = None
if isinstance(state, tuple) and len(state) == 2:
dict_state, slots_state = state
if isinstance(dict_state, dict):
inst.__dict__.update(dict_state)
if isinstance(slots_state, dict):
for slot, val in slots_state.items():
setattr(inst, slot, val)
elif isinstance(state, dict):
logger.info("Updating __dict__ of %s with state", type(inst))
inst.__dict__.update(state)
else:

if isinstance(dict_state, dict):
inst_dict = getattr(inst, "__dict__", None)
if isinstance(inst_dict, dict):
logger.info("Updating __dict__ of %s with state", type(inst))
inst_dict.update(dict_state)
elif inst_dict is not None:
for k, v in dict_state.items():
try:
setattr(inst, k, v)
except Exception:
pass
elif dict_state is not None:
logger.warning(
"Cannot update state of %s with state of type %s",
type(inst),
type(state),
type(dict_state),
)

if isinstance(slots_state, dict):
for slot, val in slots_state.items():
try:
setattr(inst, slot, val)
except Exception:
pass
except Exception as e: # pylint: disable=broad-exception-caught
logger.warning("Failed to set state on %s: %s", type(inst), e)
logger.info("Proceeding after state failure on %s", type(inst))
Expand Down