use types.FunctionType instead of new.function for py3