Skip to content

Commit d4b10ee

Browse files
committed
Polish code
1 parent bc12c2c commit d4b10ee

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

python/paddle/fluid/framework.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ def find_name(var_list, name):
533533
in_arg_names.append(arg.name)
534534
elif isinstance(arg.name, six.binary_type):
535535
in_arg_names.append(arg.name.decode())
536+
else:
537+
raise TypeError(
538+
"arguments require unicode, str or bytes, but get %s instead."
539+
% (type(arg.name)))
536540
self.desc.set_input(in_proto.name, in_arg_names)
537541
else:
538542
self.desc.set_input(in_proto.name, [])
@@ -566,7 +570,9 @@ def find_name(var_list, name):
566570
elif isinstance(arg.name, six.binary_type):
567571
out_arg_names.append(arg.name.decode())
568572
else:
569-
out_arg_names.append(six.u(arg.name))
573+
raise TypeError(
574+
"arguments require unicode, str or bytes, but get %s instead."
575+
% (type(arg.name)))
570576
arg.op = self
571577
self.desc.set_output(out_proto.name, out_arg_names)
572578

python/paddle/fluid/layer_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ def append_activation(self, input_var):
401401
return input_var
402402
if isinstance(act, six.string_types):
403403
act = {'type': act}
404+
else:
405+
raise TypeError(str(act) + " should be unicode or str")
404406

405407
if 'use_cudnn' in self.kwargs and self.kwargs.get('use_cudnn'):
406408
act['use_cudnn'] = self.kwargs.get('use_cudnn')

python/paddle/fluid/unique_name.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def switch(new_generator=None):
7070
def guard(new_generator=None):
7171
if isinstance(new_generator, six.string_types):
7272
new_generator = UniqueNameGenerator(new_generator)
73+
elif isinstance(new_generator, six.binary_type):
74+
new_generator = UniqueNameGenerator(new_generator.decode())
75+
else:
76+
raise TypeError(str(new_generator) + " should be unicode or str")
7377
old = switch(new_generator)
7478
yield
7579
switch(old)

python/paddle/reader/creator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def recordio(paths, buf_size=100):
7373
def reader():
7474
if isinstance(paths, six.string_types):
7575
path = paths
76+
elif isinstance(paths, six.binary_type):
77+
path = paths.decode()
7678
else:
7779
path = ",".join(paths)
7880
f = rec.reader(path)

0 commit comments

Comments
 (0)