Skip to content

Commit

Permalink
correct failures for registered
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckerns committed Jun 26, 2022
1 parent 60911fc commit 178e7c0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 58 deletions.
38 changes: 7 additions & 31 deletions dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,33 +194,16 @@ def ndarraysubclassinstance(obj): return False
def numpyufunc(obj): return False
def numpydtype(obj): return False

from types import GetSetDescriptorType, ClassMethodDescriptorType, \
WrapperDescriptorType, MethodDescriptorType, MemberDescriptorType, \
MethodWrapperType #XXX: unused

# make sure to add these 'hand-built' types to _typemap
if PY3:
CellType = type((lambda x: lambda y: x)(0).__closure__[0])
else:
CellType = type((lambda x: lambda y: x)(0).func_closure[0])
# new in python2.5
if sys.hexversion >= 0x20500f0:
from types import GetSetDescriptorType
if not IS_PYPY:
from types import MemberDescriptorType
else:
# oddly, MemberDescriptorType is GetSetDescriptorType
# while, member_descriptor does exist otherwise... is this a pypy bug?
class _member(object):
__slots__ = ['descriptor']
MemberDescriptorType = type(_member.descriptor)
if IS_PYPY:
WrapperDescriptorType = MethodType
MethodDescriptorType = FunctionType
ClassMethodDescriptorType = FunctionType
else:
WrapperDescriptorType = type(type.__repr__)
MethodDescriptorType = type(type.__dict__['mro'])
ClassMethodDescriptorType = type(type.__dict__['__prepare__' if PY3 else 'mro'])

MethodWrapperType = type([].__repr__)
PartialType = type(partial(int,base=2))
PartialType = type(partial(int, base=2))
SuperType = type(super(Exception, TypeError()))
ItemGetterType = type(itemgetter(0))
AttrGetterType = type(attrgetter('__repr__'))
Expand Down Expand Up @@ -717,15 +700,14 @@ def _create_typemap():
_reverse_typemap = dict(_create_typemap())
_reverse_typemap.update({
'CellType': CellType,
'MethodWrapperType': MethodWrapperType,
'PartialType': PartialType,
'SuperType': SuperType,
'ItemGetterType': ItemGetterType,
'AttrGetterType': AttrGetterType,
})

# "Incidental" implementation specific types. Unpickling these types in another
# implementation of Python (PyPy -> CPython) is not gauranteed to work
# implementation of Python (PyPy -> CPython) is not guaranteed to work

# This dictionary should contain all types that appear in Python implementations
# but are not defined in https://docs.python.org/3/library/types.html#standard-interpreter-types
Expand Down Expand Up @@ -764,16 +746,10 @@ def _create_typemap():
if InputType:
_incedental_reverse_typemap['InputType'] = InputType
_incedental_reverse_typemap['OutputType'] = OutputType
if not IS_PYPY:
_incedental_reverse_typemap['WrapperDescriptorType'] = WrapperDescriptorType
_incedental_reverse_typemap['MethodDescriptorType'] = MethodDescriptorType
_incedental_reverse_typemap['ClassMethodDescriptorType'] = ClassMethodDescriptorType
else:
_incedental_reverse_typemap['MemberDescriptorType'] = MemberDescriptorType

try:
import symtable
_incedental_reverse_typemap["SymtableStentryType"] = type(symtable.symtable("", "string", "exec")._table)
_incedental_reverse_typemap["SymtableEntryType"] = type(symtable.symtable("", "string", "exec")._table)
except:
pass

Expand Down
53 changes: 26 additions & 27 deletions dill/_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,16 @@ class _Struct(ctypes.Structure):
a['NotImplementedType'] = NotImplemented
a['SliceType'] = slice(1)
a['UnboundMethodType'] = _class._method #XXX: works when not imported!
a['TextWrapperType'] = open(os.devnull, 'r') # same as mode='w','w+','r+'
a['BufferedRandomType'] = open(os.devnull, 'r+b') # same as mode='w+b'
a['BufferedReaderType'] = open(os.devnull, 'rb') # (default: buffering=-1)
a['BufferedWriterType'] = open(os.devnull, 'wb')
d['TextWrapperType'] = open(os.devnull, 'r') # same as mode='w','w+','r+'
d['BufferedRandomType'] = open(os.devnull, 'r+b') # same as mode='w+b'
d['BufferedReaderType'] = open(os.devnull, 'rb') # (default: buffering=-1)
d['BufferedWriterType'] = open(os.devnull, 'wb')
try: # oddities: deprecated
from _pyio import open as _open
a['PyTextWrapperType'] = _open(os.devnull, 'r', buffering=-1)
a['PyBufferedRandomType'] = _open(os.devnull, 'r+b', buffering=-1)
a['PyBufferedReaderType'] = _open(os.devnull, 'rb', buffering=-1)
a['PyBufferedWriterType'] = _open(os.devnull, 'wb', buffering=-1)
d['PyTextWrapperType'] = _open(os.devnull, 'r', buffering=-1)
d['PyBufferedRandomType'] = _open(os.devnull, 'r+b', buffering=-1)
d['PyBufferedReaderType'] = _open(os.devnull, 'rb', buffering=-1)
d['PyBufferedWriterType'] = _open(os.devnull, 'wb', buffering=-1)
except ImportError:
pass
# other (concrete) object types
Expand All @@ -294,17 +294,16 @@ class _Struct(ctypes.Structure):
else:
d['CellType'] = (_lambda)(0).func_closure[0]
a['XRangeType'] = _xrange = xrange(1)
if not IS_PYPY:
d['MethodDescriptorType'] = type.__dict__['mro']
d['WrapperDescriptorType'] = type.__repr__
a['WrapperDescriptorType2'] = type.__dict__['__module__']
d['ClassMethodDescriptorType'] = type.__dict__['__prepare__' if PY3 else 'mro']
a['MethodDescriptorType'] = type.__dict__['mro']
a['WrapperDescriptorType'] = type.__repr__
#a['WrapperDescriptorType2'] = type.__dict__['__module__']#XXX: GetSetDescriptor
a['ClassMethodDescriptorType'] = type.__dict__['__prepare__' if PY3 else 'mro']
# built-in functions (CH 2)
if PY3 or IS_PYPY:
_methodwrap = (1).__lt__
else:
_methodwrap = (1).__cmp__
d['MethodWrapperType'] = _methodwrap
a['MethodWrapperType'] = _methodwrap
a['StaticMethodType'] = staticmethod(_method)
a['ClassMethodType'] = classmethod(_method)
a['PropertyType'] = property()
Expand Down Expand Up @@ -414,7 +413,7 @@ class _Struct(ctypes.Structure):

# -- dill fails in some versions below here ---------------------------------
# types module (part of CH 8)
a['FileType'] = open(os.devnull, 'rb', buffering=0) # same 'wb','wb+','rb+'
d['FileType'] = open(os.devnull, 'rb', buffering=0) # same 'wb','wb+','rb+'
# built-in functions (CH 2)
# Iterators:
a['ListIteratorType'] = iter(_list) # empty vs non-empty
Expand All @@ -427,9 +426,9 @@ class _Struct(ctypes.Structure):
x["MemoryIteratorType"] = iter(memoryview(b''))
a["ListReverseiteratorType"] = reversed([])
X = a['OrderedDictType']
a["OdictKeysType"] = X.keys()
a["OdictValuesType"] = X.values()
a["OdictItemsType"] = X.items()
d["OdictKeysType"] = X.keys()
d["OdictValuesType"] = X.values()
d["OdictItemsType"] = X.items()
a["OdictIteratorType"] = iter(X.keys())
del X
if PY3:
Expand All @@ -447,8 +446,8 @@ class _Struct(ctypes.Structure):

try:
import symtable
x["SymtableEntryType"] = symtable.symtable("", "string", "exec")._table
except:
d["SymtableEntryType"] = symtable.symtable("", "string", "exec")._table
except: #FIXME: fails; should not be registered (in _reverse__typemap)?
pass

if sys.hexversion >= 0x30a00a0:
Expand Down Expand Up @@ -555,13 +554,13 @@ class _Struct(ctypes.Structure):
x['MemoryType'] = memoryview(_in) # 2.7
x['MemoryType2'] = memoryview(bytearray(_in)) # 2.7
if PY3:
a['DictItemsType'] = _dict.items() # 2.7
a['DictKeysType'] = _dict.keys() # 2.7
a['DictValuesType'] = _dict.values() # 2.7
d['DictItemsType'] = _dict.items() # 2.7
d['DictKeysType'] = _dict.keys() # 2.7
d['DictValuesType'] = _dict.values() # 2.7
else:
a['DictItemsType'] = _dict.viewitems() # 2.7
a['DictKeysType'] = _dict.viewkeys() # 2.7
a['DictValuesType'] = _dict.viewvalues() # 2.7
d['DictItemsType'] = _dict.viewitems() # 2.7
d['DictKeysType'] = _dict.viewkeys() # 2.7
d['DictValuesType'] = _dict.viewvalues() # 2.7
# generic operating system services (CH 15)
a['RawTextHelpFormatterType'] = argparse.RawTextHelpFormatter('PROG')
a['RawDescriptionHelpFormatterType'] = argparse.RawDescriptionHelpFormatter('PROG')
Expand All @@ -580,7 +579,7 @@ class _Struct(ctypes.Structure):

from dill._dill import _testcapsule
if _testcapsule is not None:
a['PyCapsuleType'] = _testcapsule
d['PyCapsuleType'] = _testcapsule
del _testcapsule

# -- cleanup ----------------------------------------------------------------
Expand Down

0 comments on commit 178e7c0

Please sign in to comment.