Skip to content

Commit d75566d

Browse files
authored
Drop Python 3.5 compatibility code (#443)
1 parent fca7b22 commit d75566d

8 files changed

Lines changed: 50 additions & 124 deletions

File tree

cloudpickle/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import absolute_import
2-
3-
41
from cloudpickle.cloudpickle import * # noqa
52
from cloudpickle.cloudpickle_fast import CloudPickler, dumps, dump # noqa
63

cloudpickle/cloudpickle.py

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4141
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4242
"""
43-
from __future__ import print_function
4443

4544
import builtins
4645
import dis
@@ -56,7 +55,7 @@
5655

5756
from .compat import pickle
5857
from collections import OrderedDict
59-
from typing import Generic, Union, Tuple, Callable
58+
from typing import ClassVar, Generic, Union, Tuple, Callable
6059
from pickle import _getattribute
6160
from importlib._bootstrap import _find_spec
6261

@@ -66,11 +65,6 @@
6665
except ImportError:
6766
_typing_extensions = Literal = Final = None
6867

69-
if sys.version_info >= (3, 5, 3):
70-
from typing import ClassVar
71-
else: # pragma: no cover
72-
ClassVar = None
73-
7468
if sys.version_info >= (3, 8):
7569
from types import CellType
7670
else:
@@ -604,43 +598,21 @@ def parametrized_type_hint_getinitargs(obj):
604598
elif type(obj) is type(ClassVar):
605599
initargs = (ClassVar, obj.__type__)
606600
elif type(obj) is type(Generic):
607-
parameters = obj.__parameters__
608-
if len(obj.__parameters__) > 0:
609-
# in early Python 3.5, __parameters__ was sometimes
610-
# preferred to __args__
611-
initargs = (obj.__origin__, parameters)
612-
613-
else:
614-
initargs = (obj.__origin__, obj.__args__)
601+
initargs = (obj.__origin__, obj.__args__)
615602
elif type(obj) is type(Union):
616-
if sys.version_info < (3, 5, 3): # pragma: no cover
617-
initargs = (Union, obj.__union_params__)
618-
else:
619-
initargs = (Union, obj.__args__)
603+
initargs = (Union, obj.__args__)
620604
elif type(obj) is type(Tuple):
621-
if sys.version_info < (3, 5, 3): # pragma: no cover
622-
initargs = (Tuple, obj.__tuple_params__)
623-
else:
624-
initargs = (Tuple, obj.__args__)
605+
initargs = (Tuple, obj.__args__)
625606
elif type(obj) is type(Callable):
626-
if sys.version_info < (3, 5, 3): # pragma: no cover
627-
args = obj.__args__
628-
result = obj.__result__
629-
if args != Ellipsis:
630-
if isinstance(args, tuple):
631-
args = list(args)
632-
else:
633-
args = [args]
607+
(*args, result) = obj.__args__
608+
if len(args) == 1 and args[0] is Ellipsis:
609+
args = Ellipsis
634610
else:
635-
(*args, result) = obj.__args__
636-
if len(args) == 1 and args[0] is Ellipsis:
637-
args = Ellipsis
638-
else:
639-
args = list(args)
611+
args = list(args)
640612
initargs = (Callable, (args, result))
641613
else: # pragma: no cover
642614
raise pickle.PicklingError(
643-
"Cloudpickle Error: Unknown type {}".format(type(obj))
615+
f"Cloudpickle Error: Unknown type {type(obj)}"
644616
)
645617
return initargs
646618

@@ -720,7 +692,7 @@ def instance(cls):
720692

721693

722694
@instance
723-
class _empty_cell_value(object):
695+
class _empty_cell_value:
724696
"""sentinel for empty closures
725697
"""
726698
@classmethod
@@ -749,7 +721,7 @@ def _fill_function(*args):
749721
keys = ['globals', 'defaults', 'dict', 'module', 'closure_values']
750722
state = dict(zip(keys, args[1:]))
751723
else:
752-
raise ValueError('Unexpected _fill_value arguments: %r' % (args,))
724+
raise ValueError(f'Unexpected _fill_value arguments: {args!r}')
753725

754726
# - At pickling time, any dynamic global variable used by func is
755727
# serialized by value (in state['globals']).
@@ -917,15 +889,10 @@ def _make_typevar(name, bound, constraints, covariant, contravariant,
917889

918890

919891
def _decompose_typevar(obj):
920-
try:
921-
class_tracker_id = _get_or_create_tracker_id(obj)
922-
except TypeError: # pragma: nocover
923-
# TypeVar instances are not weakref-able in Python 3.5.3
924-
class_tracker_id = None
925892
return (
926893
obj.__name__, obj.__bound__, obj.__constraints__,
927894
obj.__covariant__, obj.__contravariant__,
928-
class_tracker_id,
895+
_get_or_create_tracker_id(obj),
929896
)
930897

931898

cloudpickle/cloudpickle_fast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _class_getnewargs(obj):
123123

124124

125125
def _enum_getnewargs(obj):
126-
members = dict((e.name, e.value) for e in obj)
126+
members = {e.name: e.value for e in obj}
127127
return (obj.__bases__, obj.__name__, obj.__qualname__, members,
128128
obj.__module__, _get_or_create_tracker_id(obj), None)
129129

@@ -218,7 +218,7 @@ def _class_getstate(obj):
218218
def _enum_getstate(obj):
219219
clsdict, slotstate = _class_getstate(obj)
220220

221-
members = dict((e.name, e.value) for e in obj)
221+
members = {e.name: e.value for e in obj}
222222
# Cleanup the clsdict that will be passed to _rehydrate_skeleton_class:
223223
# Those attributes are already handled by the metaclass.
224224
for attrname in ["_generate_next_value_", "_member_names_",

tests/cloudpickle_file_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
import os
42
import shutil
53
import sys

0 commit comments

Comments
 (0)