From 326a6d63aa0f69752ba38079c036647c206e7e96 Mon Sep 17 00:00:00 2001 From: Android zhang <53324261+zade23@users.noreply.github.com> Date: Mon, 25 Sep 2023 10:46:21 +0800 Subject: [PATCH] [CodeStyle][task 22] enable Ruff C417 rule in `python/paddle/base` (#57634) * fix Ruff_C417 * remove pyproject.toml/C417 --- pyproject.toml | 1 - python/paddle/base/backward.py | 14 ++------------ python/paddle/static/nn/control_flow.py | 4 +--- test/legacy_test/test_lstm_cudnn_op.py | 2 +- test/rnn/rnn_numpy.py | 2 +- 5 files changed, 5 insertions(+), 18 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b62b503c06e96..088841222c7d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,7 +109,6 @@ ignore = [ "C408", "UP030", "C405", - "C417", "B004", "B009", "B016", diff --git a/python/paddle/base/backward.py b/python/paddle/base/backward.py index 1c3c3a3f202ed..2bc6f4fd13dcf 100755 --- a/python/paddle/base/backward.py +++ b/python/paddle/base/backward.py @@ -345,22 +345,12 @@ def _create_op_desc_(op_type, inputs, outputs, attrs): for para, args in inputs.items(): op_desc.set_input( para, - list( - map( - lambda arg: arg.decode() if isinstance(arg, bytes) else arg, - args, - ) - ), + [arg.decode() if isinstance(arg, bytes) else arg for arg in args], ) for para, args in outputs.items(): op_desc.set_output( para, - list( - map( - lambda arg: arg.decode() if isinstance(arg, bytes) else arg, - args, - ) - ), + [arg.decode() if isinstance(arg, bytes) else arg for arg in args], ) op_role_attr_name = core.op_proto_and_checker_maker.kOpRoleAttrName() op_device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName() diff --git a/python/paddle/static/nn/control_flow.py b/python/paddle/static/nn/control_flow.py index 0d0afcc71c150..e5603f733883c 100644 --- a/python/paddle/static/nn/control_flow.py +++ b/python/paddle/static/nn/control_flow.py @@ -1422,9 +1422,7 @@ def _select_input_infer_shape(first_shape, second_shape): f"the input shapes of select_input should have the same rank, but get {first_shape}, {second_shape}" ) return second_shape - out_shape = list( - map(lambda a, b: a if a == b else -1, first_shape, second_shape) - ) + out_shape = [a if a == b else -1 for a, b in zip(first_shape, second_shape)] return out_shape diff --git a/test/legacy_test/test_lstm_cudnn_op.py b/test/legacy_test/test_lstm_cudnn_op.py index 2d61b7c8f9a2d..ade1f61c0d5a9 100644 --- a/test/legacy_test/test_lstm_cudnn_op.py +++ b/test/legacy_test/test_lstm_cudnn_op.py @@ -134,7 +134,7 @@ def update_state(mask, new, old): if not isinstance(old, (tuple, list)): return np.where(mask, new, old) else: - return tuple(map(lambda x, y: np.where(mask, x, y), new, old)) + return tuple(np.where(mask, x, y) for x, y in zip(new, old)) def rnn( diff --git a/test/rnn/rnn_numpy.py b/test/rnn/rnn_numpy.py index d1a7ccbf02ecb..f303b460cdb9d 100644 --- a/test/rnn/rnn_numpy.py +++ b/test/rnn/rnn_numpy.py @@ -211,7 +211,7 @@ def update_state(mask, new, old): if not isinstance(old, (tuple, list)): return np.where(mask, new, old) else: - return tuple(map(lambda x, y: np.where(mask, x, y), new, old)) + return tuple(np.where(mask, x, y) for x, y in zip(new, old)) def rnn(