From cad4926bbdcef632103a89eac0beb0f312e095c0 Mon Sep 17 00:00:00 2001 From: Leonardo Gama Date: Sat, 3 Sep 2022 00:20:47 -0300 Subject: [PATCH] save enums by reference --- dill/_dill.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dill/_dill.py b/dill/_dill.py index 0130e709..b1a1997c 100644 --- a/dill/_dill.py +++ b/dill/_dill.py @@ -60,6 +60,7 @@ # import zlib from weakref import ReferenceType, ProxyType, CallableProxyType from collections import OrderedDict +from enum import EnumMeta from functools import partial from operator import itemgetter, attrgetter GENERATOR_FAIL = False @@ -1675,9 +1676,10 @@ def save_type(pickler, obj, postproc_list=None): else: obj_name = getattr(obj, '__qualname__', getattr(obj, '__name__', None)) _byref = getattr(pickler, '_byref', None) + is_enum = isinstance(obj, EnumMeta) obj_recursive = id(obj) in getattr(pickler, '_postproc', ()) - incorrectly_named = not _locate_function(obj, pickler) - if not _byref and not obj_recursive and incorrectly_named: # not a function, but the name was held over + incorrectly_named = not _locate_function(obj, pickler) # not a function, but the name was held over + if not _byref and not is_enum and not obj_recursive and incorrectly_named: # thanks to Tom Stepleton pointing out pickler._session unneeded logger.trace(pickler, "T2: %s", obj) _dict = obj.__dict__.copy() # convert dictproxy to dict