Skip to content

Commit

Permalink
[CodeStyle][Ruff][A-[21-34]] Fix ruff Q003 diagnostic for remaining…
Browse files Browse the repository at this point in the history
… 11 files (PaddlePaddle#67583)
  • Loading branch information
gouzil authored Aug 21, 2024
1 parent 3901873 commit 9dfac2b
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 27 deletions.
8 changes: 5 additions & 3 deletions paddle/fluid/pir/dialect/op_generator/api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,9 @@ def _gen_type_promotion_logic(self, op_info, op_name):
op_info, op_name
)

x_cast = f"auto new_{x} = pir::PromoteCast(\"{x}\", {x}, promotion_type);"
x_cast = (
f'auto new_{x} = pir::PromoteCast("{x}", {x}, promotion_type);'
)
if op_info.is_sparse_op:
op_name += "sp_" if op_name[-1] == "_" else "_sp"
type_promotion_logic_str = TYPE_PROMOTION_LOGIC_TEMPLATE.format(
Expand All @@ -794,7 +796,7 @@ def _gen_type_promotion_logic(self, op_info, op_name):
op_info, op_name
)

x_cast = f"pir::PromoteCastInplace(\"{x}\", {x}, promotion_type);"
x_cast = f'pir::PromoteCastInplace("{x}", {x}, promotion_type);'

type_promotion_logic_str = TYPE_PROMOTION_LOGIC_TEMPLATE.format(
op_name=op_name,
Expand All @@ -805,7 +807,7 @@ def _gen_type_promotion_logic(self, op_info, op_name):
)
else:
type_promotion_logic_str = (
f"\n VLOG(5) << \" No Type Promotion for {op_name} api. \"; "
f'\n VLOG(5) << " No Type Promotion for {op_name} api. "; '
)

return type_promotion_logic_str
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ select = [
"RSE",

# Flake8-quotes
# "Q003",
"Q003",
"Q004",

# Refurb
Expand Down
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,13 +947,13 @@ def get_setup_requires():
setup_requires_tmp = []
for setup_requires_i in setup_requires:
if (
"<\"3.6\"" in setup_requires_i
or "<=\"3.6\"" in setup_requires_i
or "<\"3.5\"" in setup_requires_i
or "<=\"3.5\"" in setup_requires_i
or "<\"3.7\"" in setup_requires_i
or "<=\"3.7\"" in setup_requires_i
or "<\"3.8\"" in setup_requires_i
'<"3.6"' in setup_requires_i
or '<="3.6"' in setup_requires_i
or '<"3.5"' in setup_requires_i
or '<="3.5"' in setup_requires_i
or '<"3.7"' in setup_requires_i
or '<="3.7"' in setup_requires_i
or '<"3.8"' in setup_requires_i
):
continue
setup_requires_tmp += [setup_requires_i]
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_pool2d_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _get_padding_with_SAME(input_shape, pool_size, pool_stride):
paddings = [0, 0, 0, 0]
if ceil_mode is not False:
raise ValueError(
"When Attr(pool_padding) is \"VALID\", Attr(ceil_mode)"
'When Attr(pool_padding) is "VALID", Attr(ceil_mode)'
" must be False. "
"Received ceil_mode: True."
)
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_pool3d_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _get_padding_with_SAME(input_shape, pool_size, pool_stride):
paddings = [0, 0, 0, 0, 0, 0]
if ceil_mode is not False:
raise ValueError(
"When Attr(pool_padding) is \"VALID\", Attr(ceil_mode)"
'When Attr(pool_padding) is "VALID", Attr(ceil_mode)'
" must be False. "
"Received ceil_mode: True."
)
Expand Down
2 changes: 1 addition & 1 deletion test/mkldnn/test_pool2d_bf16_mkldnn_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _get_padding_with_SAME(input_shape, pool_size, pool_stride):
paddings = [0, 0, 0, 0]
if ceil_mode is not False:
raise ValueError(
"When Attr(pool_padding) is \"VALID\", Attr(ceil_mode)"
'When Attr(pool_padding) is "VALID", Attr(ceil_mode)'
" must be False. "
"Received ceil_mode: True."
)
Expand Down
2 changes: 1 addition & 1 deletion test/xpu/test_pool2d_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _get_padding_with_SAME(input_shape, pool_size, pool_stride):
paddings = [0, 0, 0, 0]
if ceil_mode is not False:
raise ValueError(
"When Attr(pool_padding) is \"VALID\", Attr(ceil_mode)"
'When Attr(pool_padding) is "VALID", Attr(ceil_mode)'
" must be False. "
"Received ceil_mode: True."
)
Expand Down
2 changes: 1 addition & 1 deletion test/xpu/test_pool3d_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _get_padding_with_SAME(input_shape, pool_size, pool_stride):
paddings = [0, 0, 0, 0, 0, 0]
if ceil_mode is not False:
raise ValueError(
"When Attr(pool_padding) is \"VALID\", Attr(ceil_mode)"
'When Attr(pool_padding) is "VALID", Attr(ceil_mode)'
" must be False. "
"Received ceil_mode: True."
)
Expand Down
2 changes: 1 addition & 1 deletion tools/CrossStackProfiler/CspFileReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _checkArgsKey(self, key, type):
f"Invalid type of key [{key}] in args dict, it should be a {type}!"
)

exec(f"self._{key} = self._args[\"{key}\"]")
exec(f'self._{key} = self._args["{key}"]')

def _align_ts(self, ts):
return ts - self._minTimeStamp
Expand Down
6 changes: 2 additions & 4 deletions tools/check_op_benchmark_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,10 @@ def update_api_info_file(fail_case_list, api_info_file):
def summary_results(check_results, api_info_file):
"""Summary results and return sys.exit code."""
for case_name in check_results["speed"]:
logging.error(f"Check speed result with case \"{case_name}\" failed.")
logging.error(f'Check speed result with case "{case_name}" failed.')

for case_name in check_results["accuracy"]:
logging.error(
f"Check accuracy result with case \"{case_name}\" failed."
)
logging.error(f'Check accuracy result with case "{case_name}" failed.')

if len(check_results["speed"]) and api_info_file:
update_api_info_file(check_results["speed"], api_info_file)
Expand Down
4 changes: 2 additions & 2 deletions tools/jetson_infer_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def run_test_first(op_list_file):
old_list = get_op_list(op_list_file)
new_list = filter(lambda x: x not in black_list, old_list)
op_test = transform_list_to_str(new_list)
os.system("ctest -R \"(" + op_test + ")\" >& test_op_log.txt")
os.system(f'ctest -R "({op_test})" >& test_op_log.txt')


def run_test_second():
Expand All @@ -289,7 +289,7 @@ def run_test_second():
+ " op(s) need to rerun!!!-------"
)
for failed_op in rerun_list:
os.system("ctest -R \"(" + failed_op + ")\" ")
os.system(f'ctest -R "({failed_op})" ')
else:
print("-------all op passed successfully!!!-------")

Expand Down
7 changes: 3 additions & 4 deletions tools/prune_for_jetson.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,10 @@ def append_fluid_kernels():
os.path.dirname(os.path.abspath(__file__))
+ "/../paddle/fluid/inference/tensorrt/CMakeLists.txt"
)
append_str = "\nfile(APPEND ${pybind_file} \"USE_NO_KERNEL_OP__(tensorrt_engine);\\n\")\n"
append_str = '\nfile(APPEND ${pybind_file} "USE_NO_KERNEL_OP__(tensorrt_engine);\\n")\n'
for op in op_white_list:
append_str = (
append_str
+ f"file(APPEND ${{pybind_file}} \"USE_OP__({op});\\n\")\n"
append_str + f'file(APPEND ${{pybind_file}} "USE_OP__({op});\\n")\n'
)

with open(file_name, 'r', encoding='utf-8') as f:
Expand All @@ -130,7 +129,7 @@ def append_fluid_kernels():
new_content = content.replace(location_str, location_str + append_str)

if new_content == content:
print(f"ERROR: can not find \"{location_str}\" in file \"{file_name}\"")
print(f'ERROR: can not find "{location_str}" in file "{file_name}"')
return False

with open(file_name, 'w', encoding='utf-8') as f:
Expand Down

0 comments on commit 9dfac2b

Please sign in to comment.