63
63
DEFAULT_PROTOCOL = pickle .HIGHEST_PROTOCOL
64
64
65
65
66
- if sys .version < '3' :
66
+ if sys .version_info [ 0 ] < 3 : # pragma: no branch
67
67
from pickle import Pickler
68
68
try :
69
69
from cStringIO import StringIO
@@ -128,7 +128,7 @@ def inner(value):
128
128
# NOTE: we are marking the cell variable as a free variable intentionally
129
129
# so that we simulate an inner function instead of the outer function. This
130
130
# is what gives us the ``nonlocal`` behavior in a Python 2 compatible way.
131
- if not PY3 :
131
+ if not PY3 : # pragma: no branch
132
132
return types .CodeType (
133
133
co .co_argcount ,
134
134
co .co_nlocals ,
@@ -229,14 +229,14 @@ def _factory():
229
229
}
230
230
231
231
232
- if sys .version_info < (3 , 4 ):
232
+ if sys .version_info < (3 , 4 ): # pragma: no branch
233
233
def _walk_global_ops (code ):
234
234
"""
235
235
Yield (opcode, argument number) tuples for all
236
236
global-referencing instructions in *code*.
237
237
"""
238
238
code = getattr (code , 'co_code' , b'' )
239
- if not PY3 :
239
+ if not PY3 : # pragma: no branch
240
240
code = map (ord , code )
241
241
242
242
n = len (code )
@@ -293,7 +293,7 @@ def save_memoryview(self, obj):
293
293
294
294
dispatch [memoryview ] = save_memoryview
295
295
296
- if not PY3 :
296
+ if not PY3 : # pragma: no branch
297
297
def save_buffer (self , obj ):
298
298
self .save (str (obj ))
299
299
@@ -315,7 +315,7 @@ def save_codeobject(self, obj):
315
315
"""
316
316
Save a code object
317
317
"""
318
- if PY3 :
318
+ if PY3 : # pragma: no branch
319
319
args = (
320
320
obj .co_argcount , obj .co_kwonlyargcount , obj .co_nlocals , obj .co_stacksize ,
321
321
obj .co_flags , obj .co_code , obj .co_consts , obj .co_names , obj .co_varnames ,
@@ -393,7 +393,7 @@ def save_function(self, obj, name=None):
393
393
# So we pickle them here using save_reduce; have to do it differently
394
394
# for different python versions.
395
395
if not hasattr (obj , '__code__' ):
396
- if PY3 :
396
+ if PY3 : # pragma: no branch
397
397
rv = obj .__reduce_ex__ (self .proto )
398
398
else :
399
399
if hasattr (obj , '__self__' ):
@@ -730,7 +730,7 @@ def save_instancemethod(self, obj):
730
730
if obj .__self__ is None :
731
731
self .save_reduce (getattr , (obj .im_class , obj .__name__ ))
732
732
else :
733
- if PY3 :
733
+ if PY3 : # pragma: no branch
734
734
self .save_reduce (types .MethodType , (obj .__func__ , obj .__self__ ), obj = obj )
735
735
else :
736
736
self .save_reduce (types .MethodType , (obj .__func__ , obj .__self__ , obj .__self__ .__class__ ),
@@ -783,7 +783,7 @@ def save_inst(self, obj):
783
783
save (stuff )
784
784
write (pickle .BUILD )
785
785
786
- if not PY3 :
786
+ if not PY3 : # pragma: no branch
787
787
dispatch [types .InstanceType ] = save_inst
788
788
789
789
def save_property (self , obj ):
@@ -883,7 +883,7 @@ def save_not_implemented(self, obj):
883
883
884
884
try : # Python 2
885
885
dispatch [file ] = save_file
886
- except NameError : # Python 3
886
+ except NameError : # Python 3 # pragma: no branch
887
887
dispatch [io .TextIOWrapper ] = save_file
888
888
889
889
dispatch [type (Ellipsis )] = save_ellipsis
@@ -904,6 +904,12 @@ def save_root_logger(self, obj):
904
904
905
905
dispatch [logging .RootLogger ] = save_root_logger
906
906
907
+ if hasattr (types , "MappingProxyType" ): # pragma: no branch
908
+ def save_mappingproxy (self , obj ):
909
+ self .save_reduce (types .MappingProxyType , (dict (obj ),), obj = obj )
910
+
911
+ dispatch [types .MappingProxyType ] = save_mappingproxy
912
+
907
913
"""Special functions for Add-on libraries"""
908
914
def inject_addons (self ):
909
915
"""Plug in system. Register additional pickling functions if modules already loaded"""
@@ -1213,7 +1219,7 @@ def _getobject(modname, attribute):
1213
1219
1214
1220
""" Use copy_reg to extend global pickle definitions """
1215
1221
1216
- if sys .version_info < (3 , 4 ):
1222
+ if sys .version_info < (3 , 4 ): # pragma: no branch
1217
1223
method_descriptor = type (str .upper )
1218
1224
1219
1225
def _reduce_method_descriptor (obj ):
0 commit comments