Skip to content

Commit

Permalink
Add incedental types to objects.py
Browse files Browse the repository at this point in the history
  • Loading branch information
anivegesana committed Jun 8, 2022
1 parent c278eda commit 465fe9a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
22 changes: 11 additions & 11 deletions dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def _create_typemap():
"BytearrayIteratorType": type(iter(bytearray(b''))),
"CallableIteratorType": type(iter(iter, None)),
"MemoryIteratorType": type(iter(memoryview(b''))),
"RangeIteratorType": type(iter(range(3))),
"XRangeIteratorType": type(iter(range(3))),
"SetIteratorType": type(iter(set())),
"TupleIteratorType": type(iter(())),

Expand All @@ -757,9 +757,9 @@ def _create_typemap():
"DictValuesType": type({}.values()),
"DictItemsType": type({}.items()),

"DictKeyiteratorType": type(iter({}.keys())),
"DictValueiteratorType": type(iter({}.values())),
"DictItemiteratorType": type(iter({}.items())),
"DictionaryKeyiteratorType": type(iter({}.keys())),
"DictionaryValueiteratorType": type(iter({}.values())),
"DictionaryItemiteratorType": type(iter({}.items())),

"OdictKeysType": type(x.keys()),
"OdictValuesType": type(x.values()),
Expand All @@ -779,9 +779,9 @@ def _create_typemap():
"DictValuesType": type({}.viewvalues()),
"DictItemsType": type({}.viewitems()),

"DictKeyiteratorType": type({}.iterkeys()),
"DictValueiteratorType": type({}.itervalues()),
"DictItemiteratorType": type({}.iteritems()),
"DictionaryKeyiteratorType": type({}.iterkeys()),
"DictionaryValueiteratorType": type({}.itervalues()),
"DictionaryItemiteratorType": type({}.iteritems()),
})

if ExitType:
Expand All @@ -805,14 +805,14 @@ def _create_typemap():
if sys.hexversion >= 0x30a00a0:
_incedental_reverse_typemap['LineIteratorType'] = type(compile('3', '', 'eval').co_lines())

if sys.hexversion >= 0x30b00a0:
# from types import GenericAlias
# _incedental_reverse_typemap["GenericAliasIteratorType"] = type(iter(GenericAlias(list, (int,))))
if sys.hexversion >= 0x30b00b0:
from types import GenericAlias
_incedental_reverse_typemap["GenericAliasIteratorType"] = type(iter(GenericAlias(list, (int,))))
_incedental_reverse_typemap['PositionsIteratorType'] = type(compile('3', '', 'eval').co_positions())

try:
import winreg
_incedental_reverse_typemap["PyHKEY"] = winreg.HKEYType
_incedental_reverse_typemap["HKEYType"] = winreg.HKEYType
except:
pass

Expand Down
48 changes: 39 additions & 9 deletions dill/_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,48 @@ class _Struct(ctypes.Structure):
a['FileType'] = open(os.devnull, 'rb', buffering=0) # same 'wb','wb+','rb+'
# FIXME: FileType fails >= 3.1
# built-in functions (CH 2)
# Iterators:
a['ListIteratorType'] = iter(_list) # empty vs non-empty FIXME: fail < 3.2
x['SetIteratorType'] = iter(_set) #XXX: empty vs non-empty
a['TupleIteratorType']= iter(_tuple) # empty vs non-empty FIXME: fail < 3.2
a['XRangeIteratorType'] = iter(_xrange) # empty vs non-empty FIXME: fail < 3.2
a["BytesIteratorType"] = iter(b'')
a["BytearrayIteratorType"] = iter(bytearray(b''))
a["CallableIteratorType"] = iter(iter, None)
a["MemoryIteratorType"] = iter(memoryview(b''))
a["ListReverseiteratorType"] = reversed([])
X = a['OrderedDictType']
a["OdictKeysType"] = X.keys()
a["OdictValuesType"] = X.values()
a["OdictItemsType"] = X.items()
a["OdictIteratorType"] = iter(X.keys())
del X
if PY3:
x['DictionaryItemIteratorType'] = iter(type.__dict__.items())
x['DictionaryKeyIteratorType'] = iter(type.__dict__.keys())
x['DictionaryValueIteratorType'] = iter(type.__dict__.values())
else:
x['DictionaryItemIteratorType'] = type.__dict__.iteritems()
x['DictionaryKeyIteratorType'] = type.__dict__.iterkeys()
x['DictionaryValueIteratorType'] = type.__dict__.itervalues()
a["DictReversekeyiteratorType"] = reversed({}.keys())
a["DictReversevalueiteratorType"] = reversed({}.values())
a["DictReverseitemiteratorType"] = reversed({}.items())

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

if sys.hexversion >= 0x30a00a0:
a['LineIteratorType'] = compile('3', '', 'eval').co_lines()

if sys.hexversion >= 0x30b00b0:
from types import GenericAlias
a["GenericAliasIteratorType"] = iter(GenericAlias(list, (int,)))
a['PositionsIteratorType'] = compile('3', '', 'eval').co_positions()

# data types (CH 8)
a['PrettyPrinterType'] = pprint.PrettyPrinter() #FIXME: fail >= 3.2 and == 2.5
# numeric and mathematical types (CH 9)
Expand Down Expand Up @@ -452,16 +491,7 @@ class _Struct(ctypes.Structure):
# other (concrete) object types
# (also: Capsule / CObject ?)
# built-in functions (CH 2)
x['SetIteratorType'] = iter(_set) #XXX: empty vs non-empty
# built-in types (CH 5)
if PY3:
x['DictionaryItemIteratorType'] = iter(type.__dict__.items())
x['DictionaryKeyIteratorType'] = iter(type.__dict__.keys())
x['DictionaryValueIteratorType'] = iter(type.__dict__.values())
else:
x['DictionaryItemIteratorType'] = type.__dict__.iteritems()
x['DictionaryKeyIteratorType'] = type.__dict__.iterkeys()
x['DictionaryValueIteratorType'] = type.__dict__.itervalues()
# string services (CH 7)
x['StructType'] = struct.Struct('c')
x['CallableIteratorType'] = _srepattern.finditer('')
Expand Down

0 comments on commit 465fe9a

Please sign in to comment.