@@ -163,7 +163,7 @@ def cell_set(cell, value):
163163 )(value )
164164
165165
166- #relevant opcodes
166+ # relevant opcodes
167167STORE_GLOBAL = opcode .opmap ['STORE_GLOBAL' ]
168168DELETE_GLOBAL = opcode .opmap ['DELETE_GLOBAL' ]
169169LOAD_GLOBAL = opcode .opmap ['LOAD_GLOBAL' ]
@@ -173,7 +173,7 @@ def cell_set(cell, value):
173173
174174
175175def islambda (func ):
176- return getattr (func ,'__name__' ) == '<lambda>'
176+ return getattr (func , '__name__' ) == '<lambda>'
177177
178178
179179_BUILTIN_TYPE_NAMES = {}
@@ -275,15 +275,18 @@ def dump(self, obj):
275275
276276 def save_memoryview (self , obj ):
277277 self .save (obj .tobytes ())
278+
278279 dispatch [memoryview ] = save_memoryview
279280
280281 if not PY3 :
281282 def save_buffer (self , obj ):
282283 self .save (str (obj ))
284+
283285 dispatch [buffer ] = save_buffer
284286
285287 def save_unsupported (self , obj ):
286288 raise pickle .PicklingError ("Cannot pickle objects of type %s" % type (obj ))
289+
287290 dispatch [types .GeneratorType ] = save_unsupported
288291
289292 # itertools objects do not pickle!
@@ -311,6 +314,7 @@ def save_module(self, obj):
311314 self .save_reduce (dynamic_subimport , (obj .__name__ , vars (obj )), obj = obj )
312315 else :
313316 self .save_reduce (subimport , (obj .__name__ ,), obj = obj )
317+
314318 dispatch [types .ModuleType ] = save_module
315319
316320 def save_codeobject (self , obj ):
@@ -331,6 +335,7 @@ def save_codeobject(self, obj):
331335 obj .co_firstlineno , obj .co_lnotab , obj .co_freevars , obj .co_cellvars
332336 )
333337 self .save_reduce (types .CodeType , args , obj = obj )
338+
334339 dispatch [types .CodeType ] = save_codeobject
335340
336341 def save_function (self , obj , name = None ):
@@ -428,6 +433,7 @@ def save_function(self, obj, name=None):
428433 else :
429434 write (pickle .GLOBAL + modname + '\n ' + name + '\n ' )
430435 self .memoize (obj )
436+
431437 dispatch [types .FunctionType ] = save_function
432438
433439 def _save_subimports (self , code , top_level_dependencies ):
@@ -633,6 +639,7 @@ def save_builtin_function(self, obj):
633639 if obj .__module__ == "__builtin__" :
634640 return self .save_global (obj )
635641 return self .save_function (obj )
642+
636643 dispatch [types .BuiltinFunctionType ] = save_builtin_function
637644
638645 def save_global (self , obj , name = None , pack = struct .pack ):
@@ -671,7 +678,8 @@ def save_instancemethod(self, obj):
671678 self .save_reduce (types .MethodType , (obj .__func__ , obj .__self__ ), obj = obj )
672679 else :
673680 self .save_reduce (types .MethodType , (obj .__func__ , obj .__self__ , obj .__self__ .__class__ ),
674- obj = obj )
681+ obj = obj )
682+
675683 dispatch [types .MethodType ] = save_instancemethod
676684
677685 def save_inst (self , obj ):
@@ -725,11 +733,13 @@ def save_inst(self, obj):
725733 def save_property (self , obj ):
726734 # properties not correctly saved in python
727735 self .save_reduce (property , (obj .fget , obj .fset , obj .fdel , obj .__doc__ ), obj = obj )
736+
728737 dispatch [property ] = save_property
729738
730739 def save_classmethod (self , obj ):
731740 orig_func = obj .__func__
732741 self .save_reduce (type (obj ), (orig_func ,), obj = obj )
742+
733743 dispatch [classmethod ] = save_classmethod
734744 dispatch [staticmethod ] = save_classmethod
735745
@@ -740,7 +750,7 @@ def __getitem__(self, item):
740750 return item
741751 items = obj (Dummy ())
742752 if not isinstance (items , tuple ):
743- items = (items , )
753+ items = (items ,)
744754 return self .save_reduce (operator .itemgetter , items )
745755
746756 if type (operator .itemgetter ) is type :
@@ -771,16 +781,16 @@ def __getattribute__(self, item):
771781 def save_file (self , obj ):
772782 """Save a file"""
773783 try :
774- import StringIO as pystringIO # we can't use cStringIO as it lacks the name attribute
784+ import StringIO as pystringIO # we can't use cStringIO as it lacks the name attribute
775785 except ImportError :
776786 import io as pystringIO
777787
778- if not hasattr (obj , 'name' ) or not hasattr (obj , 'mode' ):
788+ if not hasattr (obj , 'name' ) or not hasattr (obj , 'mode' ):
779789 raise pickle .PicklingError ("Cannot pickle files that do not map to an actual file" )
780790 if obj is sys .stdout :
781- return self .save_reduce (getattr , (sys ,'stdout' ), obj = obj )
791+ return self .save_reduce (getattr , (sys , 'stdout' ), obj = obj )
782792 if obj is sys .stderr :
783- return self .save_reduce (getattr , (sys ,'stderr' ), obj = obj )
793+ return self .save_reduce (getattr , (sys , 'stderr' ), obj = obj )
784794 if obj is sys .stdin :
785795 raise pickle .PicklingError ("Cannot pickle standard input" )
786796 if obj .closed :
@@ -938,7 +948,7 @@ def _modules_to_main(modList):
938948 if type (modname ) is str :
939949 try :
940950 mod = __import__ (modname )
941- except Exception as e :
951+ except Exception :
942952 sys .stderr .write ('warning: could not import %s\n . '
943953 'Your function may unexpectedly error due to this import failing;'
944954 'A version mismatch is likely. Specific error was:\n ' % modname )
@@ -947,17 +957,19 @@ def _modules_to_main(modList):
947957 setattr (main , mod .__name__ , mod )
948958
949959
950- #object generators:
960+ # object generators:
951961def _genpartial (func , args , kwds ):
952962 if not args :
953963 args = ()
954964 if not kwds :
955965 kwds = {}
956966 return partial (func , * args , ** kwds )
957967
968+
958969def _gen_ellipsis ():
959970 return Ellipsis
960971
972+
961973def _gen_not_implemented ():
962974 return NotImplemented
963975
@@ -1074,7 +1086,7 @@ def _rehydrate_skeleton_class(skeleton_class, class_dict):
10741086def _find_module (mod_name ):
10751087 """
10761088 Iterate over each part instead of calling imp.find_module directly.
1077- This function is able to find submodules (e.g. sickit .tree)
1089+ This function is able to find submodules (e.g. scikit .tree)
10781090 """
10791091 path = None
10801092 for part in mod_name .split ('.' ):
@@ -1085,9 +1097,11 @@ def _find_module(mod_name):
10851097 file .close ()
10861098 return path , description
10871099
1100+
10881101"""Constructors for 3rd party libraries
10891102Note: These can never be renamed due to client compatibility issues"""
10901103
1104+
10911105def _getobject (modname , attribute ):
10921106 mod = __import__ (modname , fromlist = [attribute ])
10931107 return mod .__dict__ [attribute ]
0 commit comments