79775598

Date: 2025-09-26 07:56:09
Score: 1
Natty:
Report link

I came accross this looking for a way to skip a non picklable attribute and based on JacobP's answer I'm using the below. It uses the same reference to skipped as the original instance.

def __deepcopy__(self, memo):
    cls = self.__class__
    obj = cls.__new__(cls)
    memo[id(self)] = obj
    for k, v in self.__dict__.items():
        if k not in ['skipped']:
            v = copy.deepcopy(v, memo)
        setattr(obj, k, v)
    return obj
Reasons:
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: JonM