summaryrefslogtreecommitdiffstats
path: root/Lib/pickle.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index fe86f80..4f5ad5b 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -396,6 +396,8 @@ def decode_long(data):
return int.from_bytes(data, byteorder='little', signed=True)
+_NoValue = object()
+
# Pickling machinery
class _Pickler:
@@ -542,8 +544,8 @@ class _Pickler:
return
rv = NotImplemented
- reduce = getattr(self, "reducer_override", None)
- if reduce is not None:
+ reduce = getattr(self, "reducer_override", _NoValue)
+ if reduce is not _NoValue:
rv = reduce(obj)
if rv is NotImplemented:
@@ -556,8 +558,8 @@ class _Pickler:
# Check private dispatch table if any, or else
# copyreg.dispatch_table
- reduce = getattr(self, 'dispatch_table', dispatch_table).get(t)
- if reduce is not None:
+ reduce = getattr(self, 'dispatch_table', dispatch_table).get(t, _NoValue)
+ if reduce is not _NoValue:
rv = reduce(obj)
else:
# Check for a class with a custom metaclass; treat as regular
@@ -567,12 +569,12 @@ class _Pickler:
return
# Check for a __reduce_ex__ method, fall back to __reduce__
- reduce = getattr(obj, "__reduce_ex__", None)
- if reduce is not None:
+ reduce = getattr(obj, "__reduce_ex__", _NoValue)
+ if reduce is not _NoValue:
rv = reduce(self.proto)
else:
- reduce = getattr(obj, "__reduce__", None)
- if reduce is not None:
+ reduce = getattr(obj, "__reduce__", _NoValue)
+ if reduce is not _NoValue:
rv = reduce()
else:
raise PicklingError("Can't pickle %r object: %r" %
@@ -1705,8 +1707,8 @@ class _Unpickler:
stack = self.stack
state = stack.pop()
inst = stack[-1]
- setstate = getattr(inst, "__setstate__", None)
- if setstate is not None:
+ setstate = getattr(inst, "__setstate__", _NoValue)
+ if setstate is not _NoValue:
setstate(state)
return
slotstate = None