Skip to content

Commit

Permalink
Merge branch 'master' into dataclasses-quickfix
Browse files Browse the repository at this point in the history
  • Loading branch information
anivegesana committed Jul 3, 2022
2 parents ae7427c + 3881a2b commit f35c9c0
Show file tree
Hide file tree
Showing 44 changed files with 1,219 additions and 1,317 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ install:
- python -m pip install .

script:
- for test in tests/__init__.py; do echo $test ; if [[ $COVERAGE == "true" ]]; then coverage run -a $test > /dev/null; else python $test > /dev/null; fi ; done
- for test in tests/test_*.py; do echo $test ; if [[ $COVERAGE == "true" ]]; then coverage run -a $test > /dev/null; else python $test > /dev/null; fi ; done
- for test in dill/tests/__init__.py; do echo $test ; if [[ $COVERAGE == "true" ]]; then coverage run -a $test > /dev/null; else python $test > /dev/null; fi ; done
- for test in dill/tests/test_*.py; do echo $test ; if [[ $COVERAGE == "true" ]]; then coverage run -a $test > /dev/null; else python $test > /dev/null; fi ; done

after_success:
- if [[ $COVERAGE == "true" ]]; then bash <(curl -s https://codecov.io/bash); else echo ''; fi
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ include MANIFEST.in
include pyproject.toml
include tox.ini
include scripts/*
include tests/*py
recursive-include docs *
include .*
prune .git
Expand Down
55 changes: 30 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,27 @@ a trustworthy source.

``dill`` is part of ``pathos``, a python framework for heterogeneous computing.
``dill`` is in active development, so any user feedback, bug reports, comments,
or suggestions are highly appreciated. A list of issues is located at https://github.com/uqfoundation/dill/issues, with a legacy list maintained at https://uqfoundation.github.io/project/pathos/query.
or suggestions are highly appreciated. A list of issues is located at
https://github.com/uqfoundation/dill/issues, with a legacy list maintained at
https://uqfoundation.github.io/project/pathos/query.


Major Features
--------------
``dill`` can pickle the following standard types:

* none, type, bool, int, long, float, complex, str, unicode,
* none, type, bool, int, float, complex, bytes, str,
* tuple, list, dict, file, buffer, builtin,
* both old and new style classes,
* instances of old and new style classes,
* python classes, namedtuples, dataclasses, metaclasses,
* instances of classes,
* set, frozenset, array, functions, exceptions

``dill`` can also pickle more 'exotic' standard types:

* functions with yields, nested functions, lambdas
* functions with yields, nested functions, lambdas,
* cell, method, unboundmethod, module, code, methodwrapper,
* dictproxy, methoddescriptor, getsetdescriptor, memberdescriptor,
* wrapperdescriptor, xrange, slice,
* notimplemented, ellipsis, quit
* methoddescriptor, getsetdescriptor, memberdescriptor, wrapperdescriptor,
* dictproxy, slice, notimplemented, ellipsis, quit

``dill`` cannot yet pickle these standard types:

Expand Down Expand Up @@ -133,7 +134,7 @@ There are a number of options to control serialization which are provided
as keyword arguments to several ``dill`` functions:

* with *protocol*, the pickle protocol level can be set. This uses the
same value as the ``pickle`` module, *HIGHEST_PROTOCOL* or *DEFAULT_PROTOCOL*.
same value as the ``pickle`` module, *DEFAULT_PROTOCOL*.
* with *byref=True*, ``dill`` to behave a lot more like pickle with
certain objects (like modules) pickled by reference as opposed to
attempting to pickle the object itself.
Expand Down Expand Up @@ -170,26 +171,30 @@ To aid in debugging pickling issues, use *dill.detect* which provides
tools like pickle tracing::

>>> import dill.detect
>>> dill.detect.trace(True)
>>> f = dumps(squared)
F1: <function <lambda> at 0x108899e18>
F2: <function _create_function at 0x108db7488>
# F2
Co: <code object <lambda> at 0x10866a270, file "<stdin>", line 1>
F2: <function _create_code at 0x108db7510>
# F2
# Co
D1: <dict object at 0x10862b3f0>
# D1
D2: <dict object at 0x108e42ee8>
# D2
# F1
>>> dill.detect.trace(False)
>>> with dill.detect.trace():
>>> dumps(squared)
┬ F1: <function <lambda> at 0x7fe074f8c280>
├┬ F2: <function _create_function at 0x7fe074c49c10>
│└ # F2 [34 B]
├┬ Co: <code object <lambda> at 0x7fe07501eb30, file "<stdin>", line 1>
│├┬ F2: <function _create_code at 0x7fe074c49ca0>
││└ # F2 [19 B]
│└ # Co [87 B]
├┬ D1: <dict object at 0x7fe0750d4680>
│└ # D1 [22 B]
├┬ D2: <dict object at 0x7fe074c5a1c0>
│└ # D2 [2 B]
├┬ D2: <dict object at 0x7fe074f903c0>
│├┬ D2: <dict object at 0x7fe074f8ebc0>
││└ # D2 [2 B]
│└ # D2 [23 B]
└ # F1 [180 B]

With trace, we see how ``dill`` stored the lambda (``F1``) by first storing
``_create_function``, the underlying code object (``Co``) and ``_create_code``
(which is used to handle code objects), then we handle the reference to
the global dict (``D2``). A ``#`` marks when the object is actually stored.
the global dict (``D2``) plus other dictionaries (``D1`` and ``D2``) that
save the lambda object's state. A ``#`` marks when the object is actually stored.


More Information
Expand Down
14 changes: 4 additions & 10 deletions dill/__diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
Module to show if an object has changed since it was memorised
"""

import builtins
import os
import sys
import types
try:
import numpy
HAS_NUMPY = True
except:
HAS_NUMPY = False
try:
import builtins
except ImportError:
import __builtin__ as builtins
HAS_NUMPY = False

# pypy doesn't use reference counting
getrefcount = getattr(sys, 'getrefcount', lambda x:0)
Expand All @@ -44,10 +41,7 @@ def get_attrs(obj):
if type(obj) in builtins_types \
or type(obj) is type and obj in builtins_types:
return
try:
return obj.__dict__
except:
return
return getattr(obj, '__dict__', None)


def get_seq(obj, cache={str: False, frozenset: False, list: True, set: True,
Expand Down Expand Up @@ -235,6 +229,6 @@ def _imp(*args, **kwds):

# memorise all already imported modules. This implies that this must be
# imported first for any changes to be recorded
for mod in sys.modules.values():
for mod in list(sys.modules.values()):
memorise(mod)
release_gone()
76 changes: 33 additions & 43 deletions dill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
``dill`` provides the user the same interface as the ``pickle`` module, and
also includes some additional features. In addition to pickling python
objects, ``dill`` provides the ability to save the state of an interpreter
session in a single command. Hence, it would be feasable to save an
session in a single command. Hence, it would be feasible to save an
interpreter session, close the interpreter, ship the pickled file to
another computer, open a new interpreter, unpickle the session and
thus continue from the 'saved' state of the original interpreter
Expand All @@ -42,27 +42,28 @@
``dill`` is part of ``pathos``, a python framework for heterogeneous computing.
``dill`` is in active development, so any user feedback, bug reports, comments,
or suggestions are highly appreciated. A list of issues is located at https://github.com/uqfoundation/dill/issues, with a legacy list maintained at https://uqfoundation.github.io/project/pathos/query.
or suggestions are highly appreciated. A list of issues is located at
https://github.com/uqfoundation/dill/issues, with a legacy list maintained at
https://uqfoundation.github.io/project/pathos/query.
Major Features
==============
``dill`` can pickle the following standard types:
- none, type, bool, int, long, float, complex, str, unicode,
- none, type, bool, int, float, complex, bytes, str,
- tuple, list, dict, file, buffer, builtin,
- both old and new style classes,
- instances of old and new style classes,
- python classes, namedtuples, dataclasses, metaclasses,
- instances of classes,
- set, frozenset, array, functions, exceptions
``dill`` can also pickle more 'exotic' standard types:
- functions with yields, nested functions, lambdas,
- cell, method, unboundmethod, module, code, methodwrapper,
- dictproxy, methoddescriptor, getsetdescriptor, memberdescriptor,
- wrapperdescriptor, xrange, slice,
- notimplemented, ellipsis, quit
- methoddescriptor, getsetdescriptor, memberdescriptor, wrapperdescriptor,
- dictproxy, slice, notimplemented, ellipsis, quit
``dill`` cannot yet pickle these standard types:
Expand Down Expand Up @@ -148,7 +149,7 @@
as keyword arguments to several ``dill`` functions:
* with *protocol*, the pickle protocol level can be set. This uses the
same value as the ``pickle`` module, *HIGHEST_PROTOCOL* or *DEFAULT_PROTOCOL*.
same value as the ``pickle`` module, *DEFAULT_PROTOCOL*.
* with *byref=True*, ``dill`` to behave a lot more like pickle with
certain objects (like modules) pickled by reference as opposed to
attempting to pickle the object itself.
Expand Down Expand Up @@ -185,26 +186,30 @@
tools like pickle tracing::
>>> import dill.detect
>>> dill.detect.trace(True)
>>> f = dumps(squared)
F1: <function <lambda> at 0x108899e18>
F2: <function _create_function at 0x108db7488>
# F2
Co: <code object <lambda> at 0x10866a270, file "<stdin>", line 1>
F2: <function _create_code at 0x108db7510>
# F2
# Co
D1: <dict object at 0x10862b3f0>
# D1
D2: <dict object at 0x108e42ee8>
# D2
# F1
>>> dill.detect.trace(False)
>>> with dill.detect.trace():
>>> dumps(squared)
┬ F1: <function <lambda> at 0x7fe074f8c280>
├┬ F2: <function _create_function at 0x7fe074c49c10>
│└ # F2 [34 B]
├┬ Co: <code object <lambda> at 0x7fe07501eb30, file "<stdin>", line 1>
│├┬ F2: <function _create_code at 0x7fe074c49ca0>
││└ # F2 [19 B]
│└ # Co [87 B]
├┬ D1: <dict object at 0x7fe0750d4680>
│└ # D1 [22 B]
├┬ D2: <dict object at 0x7fe074c5a1c0>
│└ # D2 [2 B]
├┬ D2: <dict object at 0x7fe074f903c0>
│├┬ D2: <dict object at 0x7fe074f8ebc0>
││└ # D2 [2 B]
│└ # D2 [23 B]
└ # F1 [180 B]
With trace, we see how ``dill`` stored the lambda (``F1``) by first storing
``_create_function``, the underlying code object (``Co``) and ``_create_code``
(which is used to handle code objects), then we handle the reference to
the global dict (``D2``). A ``#`` marks when the object is actually stored.
the global dict (``D2``) plus other dictionaries (``D1`` and ``D2``) that
save the lambda object's state. A ``#`` marks when the object is actually stored.
More Information
Expand Down Expand Up @@ -296,23 +301,9 @@
# make sure "trace" is turned off
detect.trace(False)

try:
from importlib import reload
except ImportError:
try:
from imp import reload
except ImportError:
pass

# put the objects in order, if possible
try:
from collections import OrderedDict as odict
except ImportError:
try:
from ordereddict import OrderedDict as odict
except ImportError:
odict = dict
objects = odict()
from importlib import reload

objects = {}
# local import of dill._objects
#from . import _objects
#objects.update(_objects.succeeds)
Expand Down Expand Up @@ -373,7 +364,6 @@ def extend(use_dill=True):
return

extend()
del odict


def license():
Expand Down
Loading

0 comments on commit f35c9c0

Please sign in to comment.