Skip to content

Commit

Permalink
[CodeStyle][Ruff][BUAA][C-[21-30]] Fix Ruff RSE102 diagnostic for 1…
Browse files Browse the repository at this point in the history
…0 files in `python/paddle/` and `test/` (#67125)
  • Loading branch information
Jeff114514 authored Aug 7, 2024
1 parent e8b7f97 commit 1dc2d66
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions python/paddle/utils/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def __init__(self, name: str, default: T):
self.default = default

def get(self) -> T:
raise NotImplementedError()
raise NotImplementedError

def set(self, value: T) -> None:
raise NotImplementedError()
raise NotImplementedError

def delete(self) -> None:
del os.environ[self.name]
Expand Down
2 changes: 1 addition & 1 deletion test/book/notest_understand_sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def train(
data, label, input_dim=dict_dim, class_dim=class_dim
)
else:
raise NotImplementedError()
raise NotImplementedError

adagrad = paddle.optimizer.Adagrad(learning_rate=0.002)
adagrad.minimize(cost)
Expand Down
2 changes: 1 addition & 1 deletion test/deprecated/book/test_recognize_digits_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def train(
net_conf = conv_net

if parallel:
raise NotImplementedError()
raise NotImplementedError
else:
prediction, avg_loss, acc = net_conf(img, label)

Expand Down
2 changes: 1 addition & 1 deletion test/deprecated/book/test_word2vec_book_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __network__(words):
[first_word, second_word, third_word, forth_word, next_word]
)
else:
raise NotImplementedError()
raise NotImplementedError

sgd_optimizer = paddle.optimizer.SGD(learning_rate=0.001)
if use_bf16:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __impl__():
np.random.uniform(low=-1, high=1, size=[10])
),
else:
raise ValueError()
raise ValueError

return __impl__

Expand Down Expand Up @@ -94,7 +94,7 @@ def __impl__():
self.assertEqual(num, batch_num)
except SystemError as ex:
self.assertEqual(num, 0)
raise ReaderException()
raise ReaderException
else:
for _ in range(3):
num = 0
Expand All @@ -110,7 +110,7 @@ def __impl__():
except SystemError as ex:
self.assertTrue(self.raise_exception)
self.assertEqual(num, 0)
raise ReaderException()
raise ReaderException

def test_main(self):
for p in self.places():
Expand Down
4 changes: 2 additions & 2 deletions test/distributed_passes/auto_parallel_pass_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def init(self):
pass

def get_model(self, place, **kwargs):
raise NotImplementedError()
raise NotImplementedError

def apply_passes(self):
raise NotImplementedError()
raise NotImplementedError

def apply_no_passes(self):
dist_strategy = fleet.DistributedStrategy()
Expand Down
6 changes: 3 additions & 3 deletions test/distributed_passes/dist_pass_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ def init(self):
pass

def get_model(self, place, **kwargs):
raise NotImplementedError()
raise NotImplementedError

def apply_passes(self, main_prog, startup_prog):
raise NotImplementedError()
raise NotImplementedError

def check_main(self, model=None, gpus=None, **kwargs):
pass_rets = self._distributed_launch(
Expand Down Expand Up @@ -269,7 +269,7 @@ def setUp(self):
super().setUp()

def pass_config(self):
raise NotImplementedError()
raise NotImplementedError

def apply_passes(self, main_prog, startup_prog):
passes = self.pass_config()
Expand Down
4 changes: 2 additions & 2 deletions test/ir/inference/auto_scan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,13 @@ def run_test(prog_config):
self.fail_log(
f"At least {min_success_num} programs need to ran successfully, but now only about {successful_ran_programs} programs satisfied."
)
raise AssertionError()
raise AssertionError
used_time = time.time() - start_time
if max_duration > 0 and used_time > max_duration:
self.fail_log(
f"The duration exceeds {max_duration} seconds, if this is necessary, try to set a larger number for parameter `max_duration`."
)
raise AssertionError()
raise AssertionError

def run_test(self, quant=False, prog_configs=None):
status = True
Expand Down
10 changes: 5 additions & 5 deletions test/ir/inference/test_trt_convert_prelu.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def generate_input(attrs: list[dict[str, Any]], batch):
elif attrs[0]["data_format"] == "NHWC":
return np.random.random([batch, 16, 3]).astype(np.float32)
else:
raise AssertionError()
raise AssertionError
else:
if attrs[0]["data_format"] == "NCHW":
return np.random.random([batch, 3, 16, 32]).astype(
Expand Down Expand Up @@ -72,7 +72,7 @@ def generate_alpha(attrs: list[dict[str, Any]]):
elif attrs[0]["data_format"] == "NHWC":
return np.random.random([1, 16, 3]).astype(np.float32)
else:
raise AssertionError()
raise AssertionError
else:
if attrs[0]["data_format"] == "NCHW":
return np.random.random([1, 3, 16, 32]).astype(
Expand All @@ -83,7 +83,7 @@ def generate_alpha(attrs: list[dict[str, Any]]):
np.float32
)
else:
raise AssertionError()
raise AssertionError

for batch in [1, 4]:
for dims in [0, 1, 2, 3, 4]:
Expand Down Expand Up @@ -165,7 +165,7 @@ def generate_dynamic_shape(attrs):
"input_data": [1, 16, 3]
}
else:
raise AssertionError()
raise AssertionError
else:
if attrs[0]["data_format"] == "NCHW":
self.dynamic_shape.min_input_shape = {
Expand All @@ -188,7 +188,7 @@ def generate_dynamic_shape(attrs):
"input_data": [1, 16, 32, 3]
}
else:
raise AssertionError()
raise AssertionError

def clear_dynamic_shape():
self.dynamic_shape.max_input_shape = {}
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/check_nan_inf_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def check(use_cuda):
if __name__ == '__main__':
try:
check(use_cuda=False)
raise AssertionError()
raise AssertionError
except Exception as e:
print(e)
print(type(e))
Expand All @@ -108,7 +108,7 @@ def check(use_cuda):
if core.is_compiled_with_cuda():
try:
check(use_cuda=True)
raise AssertionError()
raise AssertionError
except Exception as e:
print(e)
print(type(e))
Expand Down

0 comments on commit 1dc2d66

Please sign in to comment.