#extend(False) #import cloudpickle as pickle # helper objects class _class: def _method(self): pass # objects that *fail* if imported special = {} special['LambdaType'] = _lambda = lambda x: lambda y: x special['MethodType'] = _method = _class()._method special['UnboundMethodType'] = _class._method objects.update(special) def pickles(name, exact=False): """quick check if object pickles with dill""" obj = objects[name] try: pik = pickle.loads(pickle.dumps(obj)) if exact: try: assert pik == obj except AssertionError: assert type(obj) == type(pik) print("weak: %s %s" % (name, type(obj))) else: assert type(obj) == type(pik)
# get all objects for testing from dill import load_types load_types(pickleable=True,unpickleable=False) #load_types(pickleable=True,unpickleable=True) from dill import objects # helper objects class _class: def _method(self): pass # objects that *fail* if imported special = {} special['LambdaType'] = _lambda = lambda x: lambda y: x special['MethodType'] = _method = _class()._method special['UnboundMethodType'] = _class._method objects.update(special) def pickles(name, exact=False): """quick check if object pickles with dill""" obj = objects[name] try: pik = pickle.loads(pickle.dumps(obj)) if exact: try: assert pik == obj except AssertionError: assert type(obj) == type(pik) print ("weak: %s %s" % (name, type(obj))) else: assert type(obj) == type(pik) except Exception: