Skip to content

Commit

Permalink
Kickstart support drop for Python < 3.7 (#499)
Browse files Browse the repository at this point in the history
* Kickstart support drop for Python < 3.7

Step 1 of code clean-up: mechanically remove if-else branches that would never
run in Python/PyPy >= 3.7.  There's still some unused or redundant code, left
for the next step to facilitate review.

Note: all the remaining `sys.hexversion` tests were standardized to use
numerical comparison and hexadecimal integer literals (e.g. `0x30b00a7` for
version 3.11.0a7) as most of them already were.

* convert single function defined via exec() due to Python2/3 differences

* drop 'from __future__ import print_function' statements

* remove conditional imports due to Python 2 and old Python 3

* substitute bare 'except' clauses by 'except Exception' or more specific where it's obvious

* split module imports into separated lines

* idem, but for test files

* review: adjustments

* tests: get a default Python 3 executable

* update module docs

* update README

* review: corrections

* remove unicode prefix from strings in docs/source/conf.py
  • Loading branch information
leogama committed Jul 1, 2022
1 parent 9000ab9 commit 4220929
Show file tree
Hide file tree
Showing 27 changed files with 461 additions and 1,082 deletions.
19 changes: 10 additions & 9 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
12 changes: 3 additions & 9 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
40 changes: 13 additions & 27 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 @@ -300,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 @@ -377,7 +364,6 @@ def extend(use_dill=True):
return

extend()
del odict


def license():
Expand Down

0 comments on commit 4220929

Please sign in to comment.