Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix object classification in _objects #518

Closed
mmckerns opened this issue Jun 25, 2022 · 0 comments · Fixed by #519
Closed

fix object classification in _objects #518

mmckerns opened this issue Jun 25, 2022 · 0 comments · Fixed by #519
Labels
Milestone

Comments

@mmckerns
Copy link
Member

mmckerns commented Jun 25, 2022

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'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant