@@ -756,22 +756,6 @@ def _load_type(name):
756756def _create_type (typeobj , * args ):
757757 return typeobj (* args )
758758
759- def _create_function (fcode , fglobals , fname = None , fdefaults = None ,
760- fclosure = None , fdict = None , fkwdefaults = None ):
761- # same as FunctionType, but enable passing __dict__ to new function,
762- # __dict__ is the storehouse for attributes added after function creation
763- func = FunctionType (fcode , fglobals or dict (), fname , fdefaults , fclosure )
764- if fdict is not None :
765- func .__dict__ .update (fdict ) #XXX: better copy? option to copy?
766- if fkwdefaults is not None :
767- func .__kwdefaults__ = fkwdefaults
768- # 'recurse' only stores referenced modules/objects in fglobals,
769- # thus we need to make sure that we have __builtins__ as well
770- if "__builtins__" not in func .__globals__ :
771- func .__globals__ ["__builtins__" ] = globals ()["__builtins__" ]
772- # assert id(fglobals) == id(func.__globals__)
773- return func
774-
775759def _create_code (* args ):
776760 if PY3 and hasattr (args [- 3 ], 'encode' ): #FIXME: from PY2 fails (optcode)
777761 args = list (args )
@@ -1905,6 +1889,7 @@ def save_function(pickler, obj):
19051889 # recurse to get all globals referred to by obj
19061890 from .detect import globalvars
19071891 globs_copy = globalvars (obj , recurse = True , builtin = True )
1892+ globs_copy .setdefault ('__builtins__' , globals ()['__builtins__' ])
19081893
19091894 # Add the name of the module to the globs dictionary to prevent
19101895 # the duplication of the dictionary. Pickle the unpopulated
@@ -1960,7 +1945,7 @@ def save_function(pickler, obj):
19601945 if state_dict :
19611946 state = state , state_dict
19621947
1963- _save_with_postproc (pickler , (_create_function , (
1948+ _save_with_postproc (pickler , (FunctionType , (
19641949 obj .__code__ , globs , obj .__name__ , obj .__defaults__ ,
19651950 closure
19661951 ), state ), obj = obj , postproc_list = postproc_list )
@@ -1973,7 +1958,7 @@ def save_function(pickler, obj):
19731958 if obj .__dict__ :
19741959 postproc_list .append ((setattr , (obj , '__dict__' , obj .__dict__ )))
19751960
1976- _save_with_postproc (pickler , (_create_function , (
1961+ _save_with_postproc (pickler , (FunctionType , (
19771962 obj .func_code , globs , obj .func_name , obj .func_defaults ,
19781963 closure
19791964 )), obj = obj , postproc_list = postproc_list )
0 commit comments