From d4b10eef5f79c86d4101bb89e8672c6cebbac8d4 Mon Sep 17 00:00:00 2001 From: minqiyang Date: Fri, 10 Aug 2018 17:16:54 +0800 Subject: [PATCH] Polish code --- python/paddle/fluid/framework.py | 8 +++++++- python/paddle/fluid/layer_helper.py | 2 ++ python/paddle/fluid/unique_name.py | 4 ++++ python/paddle/reader/creator.py | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 82ff62ff75..3d7c29c6ea 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -533,6 +533,10 @@ class Operator(object): in_arg_names.append(arg.name) elif isinstance(arg.name, six.binary_type): in_arg_names.append(arg.name.decode()) + else: + raise TypeError( + "arguments require unicode, str or bytes, but get %s instead." + % (type(arg.name))) self.desc.set_input(in_proto.name, in_arg_names) else: self.desc.set_input(in_proto.name, []) @@ -566,7 +570,9 @@ class Operator(object): elif isinstance(arg.name, six.binary_type): out_arg_names.append(arg.name.decode()) else: - out_arg_names.append(six.u(arg.name)) + raise TypeError( + "arguments require unicode, str or bytes, but get %s instead." + % (type(arg.name))) arg.op = self self.desc.set_output(out_proto.name, out_arg_names) diff --git a/python/paddle/fluid/layer_helper.py b/python/paddle/fluid/layer_helper.py index 64337465ed..0c2b1eb795 100644 --- a/python/paddle/fluid/layer_helper.py +++ b/python/paddle/fluid/layer_helper.py @@ -401,6 +401,8 @@ class LayerHelper(object): return input_var if isinstance(act, six.string_types): act = {'type': act} + else: + raise TypeError(str(act) + " should be unicode or str") if 'use_cudnn' in self.kwargs and self.kwargs.get('use_cudnn'): act['use_cudnn'] = self.kwargs.get('use_cudnn') diff --git a/python/paddle/fluid/unique_name.py b/python/paddle/fluid/unique_name.py index d4e28f4b91..36af91eab4 100644 --- a/python/paddle/fluid/unique_name.py +++ b/python/paddle/fluid/unique_name.py @@ -70,6 +70,10 @@ def switch(new_generator=None): def guard(new_generator=None): if isinstance(new_generator, six.string_types): new_generator = UniqueNameGenerator(new_generator) + elif isinstance(new_generator, six.binary_type): + new_generator = UniqueNameGenerator(new_generator.decode()) + else: + raise TypeError(str(new_generator) + " should be unicode or str") old = switch(new_generator) yield switch(old) diff --git a/python/paddle/reader/creator.py b/python/paddle/reader/creator.py index 369ff5e22b..c861020225 100644 --- a/python/paddle/reader/creator.py +++ b/python/paddle/reader/creator.py @@ -73,6 +73,8 @@ def recordio(paths, buf_size=100): def reader(): if isinstance(paths, six.string_types): path = paths + elif isinstance(paths, six.binary_type): + path = paths.decode() else: path = ",".join(paths) f = rec.reader(path) -- GitLab