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

Add slice type to reverse typemap #371

Conversation

zhenruiliao
Copy link

SliceType was missing from _reverse_typemap, which led to KeyError: 'SliceType' when _load_type is called. I add SliceType to _reverse_typemap explicitly

@mmckerns
Copy link
Member

mmckerns commented Jun 9, 2020

@zhenruiliao: slice is already in the reverse_typemap. Can you shed some light on why this change is necessary?

@zhenruiliao
Copy link
Author

we are getting KeyError: 'SliceType' when _load_type when unpickling objects with slices as data in our production code, which this change solved. The classes that have this problem are relatively complex but I will try to reproduce with a minimal example

@mmckerns
Copy link
Member

Can you also check if this is true:

>>> import dill
>>> 'slice' in dill._dill._reverse_typemap.keys()
True
>>> slice in dill.Pickler.dispatch.keys()
True
>>>

@mmckerns
Copy link
Member

If you look at what's in the reverse typemap, the keys are generally the names that are used in builtins and then from types. So, slice is preferred over SliceType. Also, if SliceType is needed, then BoolType and so on should also be needed as keys.

>>> import dill
>>> dill._dill._reverse_typemap.keys()
dict_keys(['bool', 'memoryview', 'bytearray', 'bytes', 'classmethod', 'complex', 'dict', 'enumerate', 'filter', 'float', 'frozenset', 'property', 'int', 'list', 'map', 'object', 'range', 'reversed', 'set', 'slice', 'staticmethod', 'str', 'super', 'tuple', 'type', 'zip', 'BaseException', 'Exception', 'TypeError', 'StopAsyncIteration', 'StopIteration', 'GeneratorExit', 'SystemExit', 'KeyboardInterrupt', 'ImportError', 'ModuleNotFoundError', 'OSError', 'EnvironmentError', 'IOError', 'EOFError', 'RuntimeError', 'RecursionError', 'NotImplementedError', 'NameError', 'UnboundLocalError', 'AttributeError', 'SyntaxError', 'IndentationError', 'TabError', 'LookupError', 'IndexError', 'KeyError', 'ValueError', 'UnicodeError', 'UnicodeEncodeError', 'UnicodeDecodeError', 'UnicodeTranslateError', 'AssertionError', 'ArithmeticError', 'FloatingPointError', 'OverflowError', 'ZeroDivisionError', 'SystemError', 'ReferenceError', 'MemoryError', 'BufferError', 'Warning', 'UserWarning', 'DeprecationWarning', 'PendingDeprecationWarning', 'SyntaxWarning', 'RuntimeWarning', 'FutureWarning', 'ImportWarning', 'UnicodeWarning', 'BytesWarning', 'ResourceWarning', 'ConnectionError', 'BlockingIOError', 'BrokenPipeError', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionRefusedError', 'ConnectionResetError', 'FileExistsError', 'FileNotFoundError', 'IsADirectoryError', 'NotADirectoryError', 'InterruptedError', 'PermissionError', 'ProcessLookupError', 'TimeoutError', 'FunctionType', 'LambdaType', 'CodeType', 'MappingProxyType', 'GeneratorType', 'CoroutineType', 'AsyncGeneratorType', 'MethodType', 'BuiltinFunctionType', 'BuiltinMethodType', 'WrapperDescriptorType', 'MethodWrapperType', 'MethodDescriptorType', 'ClassMethodDescriptorType', 'ModuleType', 'TracebackType', 'FrameType', 'GetSetDescriptorType', 'MemberDescriptorType', 'CellType', 'PartialType', 'SuperType', 'ItemGetterType', 'AttrGetterType', 'FileType', 'BufferedRandomType', 'BufferedReaderType', 'BufferedWriterType', 'TextWrapperType', 'PyBufferedRandomType', 'PyBufferedReaderType', 'PyBufferedWriterType', 'PyTextWrapperType', 'DictKeysType', 'DictValuesType', 'DictItemsType', 'OdictKeysType', 'OdictValuesType', 'OdictItemsType', 'ExitType', 'SymtableStentryType', 'PyCapsuleType'])

Related to some of the conversation in #472.

I'm going to close this. However, if you can provide a case that demonstrates how SliceType etc is needed, then we should reopen it.

@mmckerns mmckerns closed this Jun 25, 2022
@mmckerns mmckerns added this to the dill-0.3.6 milestone Jun 25, 2022
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 this pull request may close these issues.

3 participants