uqfoundation/dill

fix object classification in _objects

Closed this issue · 0 comments

dill._objects categorizes objects into three dicts:

# objects used by dill for type declaration
registered = d = odict()
# objects dill fails to pickle
failures = x = odict()
# all other type objects
succeeds = a = odict()

Apparently, this has not been updated for recent changes:

>>> import dill
>>> from dill._objects import failures, registered, succeeds
>>> import warnings
>>> warnings.filterwarnings('ignore')
>>> def check(d, ok=True):
...   res = []
...   for k,v in d.items():
...     try:
...       z = dill.copy(v)
...       if ok: res.append(k)
...     except:
...       if not ok: res.append(k)
...   return res
... 
>>> check(failures) # should be empty
['SetIteratorType', 'DictionaryItemIteratorType', 'DictionaryKeyIteratorType', 'DictionaryValueIteratorType', 'MethodCallerType', 'DictItemsType', 'DictKeysType', 'DictValuesType', 'RawTextHelpFormatterType', 'RawDescriptionHelpFormatterType', 'ArgDefaultsHelpFormatterType', 'PyCapsuleType']
>>> check(registered, ok=False) # should be empty
[]
>>> check(succeeds, ok=False) # should be empty
['CLibraryLoaderType', 'ConnectionType', 'CursorType', 'BZ2FileType', 'BZ2CompressorType', 'BZ2DecompressorType', 'DialectType', 'SocketType', 'SocketPairType', 'MemoryIteratorType', 'SymtableEntryType', 'GzipFileType']
>>> import builtins
>>> import types
>>> q = dill._dill._reverse_typemap
>>> p = {k:v for k,v in q.items() if k not in vars(builtins) and k not in vars(types)}
>>> set(p.keys()).difference(registered.keys()) # should be empty
{'OdictItemsType', 'DictKeysType', 'PyBufferedWriterType', 'PyCapsuleType', 'PyBufferedRandomType', 'OdictValuesType', 'DictValuesType', 'BufferedRandomType', 'SymtableStentryType', 'TextWrapperType', 'PyTextWrapperType', 'BufferedWriterType', 'DictItemsType', 'OdictKeysType', 'PyBufferedReaderType', 'FileType', 'BufferedReaderType'}
>>> set(registered.keys()).difference(p.keys())
{'ClassMethodDescriptorType', 'MethodWrapperType', 'MethodDescriptorType', 'WrapperDescriptorType'}