未验证 提交 85e20755 编写于 作者: 张春乔 提交者: GitHub

[CodeStyle][UP028] using yield from (#52059)

上级 33b289d7
......@@ -70,7 +70,7 @@ select = [
"UP025",
"UP026",
# "UP027",
# "UP028",
"UP028",
"UP029",
# "UP030",
# "UP031",
......
......@@ -93,8 +93,7 @@ def reader_creator(pos_pattern, neg_pattern, word_idx):
load(neg_pattern, INS, 1)
def reader():
for doc, label in INS:
yield doc, label
yield from INS
return reader
......
......@@ -228,8 +228,7 @@ class DataGenerator:
'''
def local_iter():
for sample in samples:
yield sample
yield from samples
return local_iter
......
......@@ -192,8 +192,7 @@ def reader_creator(pos_pattern, neg_pattern, word_idx):
load(neg_pattern, INS, 1)
def reader():
for doc, label in INS:
yield doc, label
yield from INS
return reader
......
......@@ -19,8 +19,7 @@ from paddle.fluid.framework import Variable
def cyclic_reader(reader):
def __reader__():
while True:
for data in reader():
yield data
yield from reader()
return __reader__
......
......@@ -105,8 +105,7 @@ class TestNoGradClass(unittest.TestCase):
)
def test_gen():
for i in range(3):
yield i
yield from range(3)
a = 0
for i in test_gen():
......@@ -114,8 +113,7 @@ class TestNoGradClass(unittest.TestCase):
@paddle.no_grad()
def test_wrapped_gen():
for i in range(3):
yield i
yield from range(3)
b = 0
for i in test_wrapped_gen():
......@@ -151,8 +149,7 @@ class TestEnableGradClass(unittest.TestCase):
)
def test_gen():
for i in range(3):
yield i
yield from range(3)
a = 0
for i in test_gen():
......@@ -160,8 +157,7 @@ class TestEnableGradClass(unittest.TestCase):
@paddle.enable_grad()
def test_wrapped_gen():
for i in range(3):
yield i
yield from range(3)
b = 0
for i in test_wrapped_gen():
......@@ -215,8 +211,7 @@ class TestSetGradEnabledClass(unittest.TestCase):
)
def test_gen():
for i in range(3):
yield i
yield from range(3)
a = 0
for i in test_gen():
......@@ -224,8 +219,7 @@ class TestSetGradEnabledClass(unittest.TestCase):
@paddle.set_grad_enabled(True)
def test_wrapped_gen():
for i in range(3):
yield i
yield from range(3)
b = 0
for i in test_wrapped_gen():
......
......@@ -212,8 +212,7 @@ def get_feed_data_reader():
all_batch_tensors.append(tensors)
def __reader__():
for t in all_batch_tensors:
yield t
yield from all_batch_tensors
feed_data_reader = FeedDataReader(
feed_list=transformer_model.build_inputs(
......
......@@ -206,8 +206,7 @@ class LayerObjectHelper(LayerHelperBase):
inputs = inputs_in if (inputs_in is not None) else []
inputs = self._multiple_input(inputs)
param_attrs = self._multiple_param_attr(len(inputs), param_attr_in)
for ipt, param_attr in zip(inputs, param_attrs):
yield ipt, param_attr
yield from zip(inputs, param_attrs)
def input_dtype(self, inputs_in):
"""Get input data type
......
......@@ -76,8 +76,7 @@ def cache(reader):
all_data = tuple(reader())
def __impl__():
for item in all_data:
yield item
yield from all_data
return __impl__
......@@ -118,8 +117,7 @@ def map_readers(func, *readers):
rs = []
for r in readers:
rs.append(r())
for e in map(func, *rs):
yield e
yield from map(func, *rs)
return reader
......@@ -228,8 +226,7 @@ def chain(*readers):
for r in readers:
rs.append(r())
for e in itertools.chain(*rs):
yield e
yield from itertools.chain(*rs)
return reader
......
......@@ -152,8 +152,7 @@ def _yield_value(iterable):
for key in _sorted(iterable):
yield iterable[key]
else:
for value in iterable:
yield value
yield from iterable
def _yield_flat_nest(nest):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册