diff -r 9487c290e088 Lib/enum.py --- a/Lib/enum.py Sun Feb 16 14:53:55 2014 -0500 +++ b/Lib/enum.py Mon Feb 17 08:54:35 2014 +0200 @@ -115,14 +115,6 @@ # Reverse value->name map for hashable values. enum_class._value2member_map_ = {} - # check for a supported pickle protocols, and if not present sabotage - # pickling, since it won't work anyway - if member_type is not object: - methods = ('__getnewargs_ex__', '__getnewargs__', - '__reduce_ex__', '__reduce__') - if not any(map(member_type.__dict__.get, methods)): - _make_class_unpicklable(enum_class) - # instantiate them, checking for duplicates as we go # we instantiate first instead of checking for duplicates first in case # a custom __new__ is doing something funky with the values -- such as @@ -167,7 +159,7 @@ # double check that repr and friends are not the mixin's or various # things break (such as pickle) - for name in ('__repr__', '__str__', '__format__', '__getnewargs__', '__reduce_ex__'): + for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'): class_method = getattr(enum_class, name) obj_method = getattr(member_type, name, None) enum_method = getattr(first_enum, name, None) @@ -465,14 +457,13 @@ val = self.value return cls.__format__(val, format_spec) - def __getnewargs__(self): - return (self._value_, ) - def __hash__(self): return hash(self._name_) def __reduce_ex__(self, proto): - return self.__class__, self.__getnewargs__() + if proto < 4: + return getattr, (self.__class__, self._name_) + return self.__class__.__qualname__ + '.' + self._name_ # DynamicClassAttribute is used to provide access to the `name` and # `value` properties of enum members while keeping some measure of diff -r 9487c290e088 Lib/test/test_enum.py --- a/Lib/test/test_enum.py Sun Feb 16 14:53:55 2014 -0500 +++ b/Lib/test/test_enum.py Mon Feb 17 08:54:35 2014 +0200 @@ -1174,9 +1174,10 @@ globals()['NEI'] = NEI NI5 = NamedInt('test', 5) self.assertEqual(NI5, 5) + for protocol in range(2, HIGHEST_PROTOCOL + 1): + self.assertRaises(TypeError, loads, dumps(NI5, protocol=protocol)) self.assertEqual(NEI.y.value, 2) - test_pickle_exception(self.assertRaises, TypeError, NEI.x) - test_pickle_exception(self.assertRaises, PicklingError, NEI) + test_pickle_dump_load(self.assertIs, NEI.y) def test_tuple_subclass(self): class SomeTuple(tuple, Enum):