Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeStyle][task 12] enable Ruff UP028 rule in python/paddle/base #57405

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ ignore = [
"F522",
"B010",
"PLR1722",
"UP028",
"C403",
"F811",
"UP034",
Expand Down Expand Up @@ -165,15 +164,6 @@ ignore = [
"test/legacy_test/test_tensordot.py" = ["B017"]
"test/legacy_test/test_top_k_v2_op.py" = ["B017"]

# UP028
"python/paddle/dataset/cifar.py" = ["UP028"]
"python/paddle/dataset/common.py" = ["UP028", "UP032"]
"python/paddle/io/dataloader/dataset.py" = ["UP028"]
"python/paddle/nn/layer/layers.py" = ["UP028", "UP032"]
"python/paddle/utils/layers_utils.py" = ["UP028", "UP032"]
"test/legacy_test/test_lstm_cudnn_op.py" = ["UP028", "UP032"]
"test/rnn/rnn_numpy.py" = ["UP028", "UP032"]

# UP032
"paddle/fluid/ir/dialect/op_generator/api_gen.py" = ["UP032"]
"paddle/fluid/ir/dialect/op_generator/op_gen.py" = ["UP032"]
Expand All @@ -190,6 +180,7 @@ ignore = [
"python/paddle/audio/backends/init_backend.py" = ["UP032"]
"python/paddle/audio/backends/wave_backend.py" = ["UP032"]
"python/paddle/batch.py" = ["UP032"]
"python/paddle/dataset/common.py" = ["UP032"]
"python/paddle/device/cuda/__init__.py" = ["UP032"]
"python/paddle/distributed/auto_parallel/interface.py" = ["UP032"]
"python/paddle/distributed/auto_parallel/static/completion.py" = ["UP032"]
Expand Down Expand Up @@ -312,6 +303,7 @@ ignore = [
"python/paddle/nn/layer/activation.py" = ["UP032"]
"python/paddle/nn/layer/common.py" = ["UP032"]
"python/paddle/nn/layer/container.py" = ["UP032"]
"python/paddle/nn/layer/layers.py" = ["UP032"]
"python/paddle/nn/layer/loss.py" = ["UP032"]
"python/paddle/nn/layer/norm.py" = ["UP032"]
"python/paddle/nn/layer/pooling.py" = ["UP032"]
Expand Down Expand Up @@ -346,6 +338,7 @@ ignore = [
"python/paddle/utils/dlpack.py" = ["UP032"]
"python/paddle/utils/download.py" = ["UP032"]
"python/paddle/utils/install_check.py" = ["UP032"]
"python/paddle/utils/layers_utils.py" = ["UP032"]
"python/paddle/vision/datasets/cifar.py" = ["UP032"]
"python/paddle/vision/datasets/flowers.py" = ["UP032"]
"python/paddle/vision/datasets/mnist.py" = ["UP032"]
Expand Down Expand Up @@ -437,6 +430,7 @@ ignore = [
"test/legacy_test/test_imperative_se_resnext.py" = ["UP032"]
"test/legacy_test/test_inplace.py" = ["UP032"]
"test/legacy_test/test_layers.py" = ["UP032"]
"test/legacy_test/test_lstm_cudnn_op.py" = ["UP032"]
"test/legacy_test/test_multi_dot_op.py" = ["UP032"]
"test/legacy_test/test_multiprocess_dataloader_iterable_dataset_static.py" = ["UP032"]
"test/legacy_test/test_multiprocess_dataloader_static.py" = ["UP032"]
Expand Down Expand Up @@ -464,6 +458,7 @@ ignore = [
"test/quantization/test_post_training_quantization_while.py" = ["UP032"]
"test/quantization/test_quant_post_quant_aware.py" = ["UP032"]
"test/quantization/test_weight_quantization_mobilenetv1.py" = ["UP032"]
"test/rnn/rnn_numpy.py" = ["UP032"]
"test/tokenizer/bert_tokenizer.py" = ["UP032"]
"test/tokenizer/tokenizer_utils.py" = ["UP032"]
"test/xpu/test_generate_proposals_v2_op_xpu.py" = ["UP032"]
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/base/dygraph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ def _decorate_function(func, *args, **kwargs):
def _decorate_generator(func, *args, **kwargs):
gen = func(*args, **kwargs)
with self:
for x in gen:
yield x
yield from gen

if inspect.isgeneratorfunction(func):
return _decorate_generator(func)
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/base/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -6956,8 +6956,7 @@ def list_vars(self):
>>> # var label : LOD_TENSOR.shape(-1, 1).dtype(int64).stop_gradient(True)
"""
for each_block in self.blocks:
for each_var in list(each_block.vars.values()):
yield each_var
yield from list(each_block.vars.values())

def all_parameters(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/base/incubate/checkpoint/auto_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,7 @@ def _get_checker():
def _normal_yield(max_epoch_num):
if max_epoch_num < 0:
max_epoch_num = sys.maxint
for i in range(0, max_epoch_num):
yield i
yield from range(0, max_epoch_num)

return

Expand Down
3 changes: 1 addition & 2 deletions python/paddle/base/layer_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def multiple_param_attr(self, length):
def iter_inputs_and_params(self, input_param_name='input'):
inputs = self.multiple_input(input_param_name)
param_attrs = self.multiple_param_attr(len(inputs))
for ipt, param_attr in zip(inputs, param_attrs):
yield ipt, param_attr
yield from zip(inputs, param_attrs)

def input_dtype(self, input_param_name='input'):
inputs = self.multiple_input(input_param_name)
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/dataset/cifar.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def reader():

for name in names:
batch = pickle.load(f.extractfile(name), encoding='bytes')
for item in read_batch(batch):
yield item
yield from read_batch(batch)

if not cycle:
break
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/dataset/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ def reader():
for fn in my_file_list:
with open(fn, "r") as f:
lines = loader(f)
for line in lines:
yield line
yield from lines

return reader

Expand Down
3 changes: 1 addition & 2 deletions python/paddle/io/dataloader/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ def __init__(self, datasets):

def __iter__(self):
for dataset in self.datasets:
for sample in dataset:
yield sample
yield from dataset


class Subset(Dataset):
Expand Down
5 changes: 2 additions & 3 deletions python/paddle/nn/layer/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,10 +1110,9 @@ def named_sublayers(self, prefix='', include_self=False, layers_set=None):
if layer is None:
continue
layer_prefix = prefix + ('.' if prefix else '') + key
for p, l in layer.named_sublayers(
yield from layer.named_sublayers(
prefix=layer_prefix, include_self=True, layers_set=layers_set
):
yield p, l
)

def register_buffer(self, name, tensor, persistable=True):
"""
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/utils/layers_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ def _yield_value(iterable):
def _yield_flat_nest(nest):
for n in _yield_value(nest):
if is_sequence(n):
for ni in _yield_flat_nest(n):
yield ni
yield from _yield_flat_nest(n)
else:
yield n

Expand Down
3 changes: 1 addition & 2 deletions test/legacy_test/test_lstm_cudnn_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ def flatten(nested):
def _flatten(nested):
for item in nested:
if isinstance(item, (list, tuple)):
for subitem in _flatten(item):
yield subitem
yield from _flatten(item)
else:
yield item

Expand Down
3 changes: 1 addition & 2 deletions test/rnn/rnn_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ def flatten(nested):
def _flatten(nested):
for item in nested:
if isinstance(item, (list, tuple)):
for subitem in _flatten(item):
yield subitem
yield from _flatten(item)
else:
yield item

Expand Down