Skip to content

Commit

Permalink
[Docathon][CodeStyle Fix No.3] enable UP032 rule (#6261)
Browse files Browse the repository at this point in the history
* enable UP032

* Update docs/api/extract_api_from_docs.py

Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>

---------

Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>
  • Loading branch information
ooooo-create and SigureMo authored Oct 29, 2023
1 parent ab3f51b commit ca4b164
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions docs/api/extract_api_from_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def find_all_paddle_api_from_code_block(cbstr):
if (sharp_ind < 0 or mo_i.start() < sharp_ind) and mo_i.group(
1
).startswith('paddle'):
api_set.add('{}.{}'.format(mo_i.group(1), mo_i.group(2)))
api_set.add(f'{mo_i.group(1)}.{mo_i.group(2)}')
else:
mo_n = normal_pat.finditer(line)
for mo in mo_n:
Expand Down Expand Up @@ -396,15 +396,15 @@ def parse_args():

if __name__ == "__main__":
args = parse_args()
print('{}'.format(args))
print(args)
logger.setLevel(logging.DEBUG)
apis_dict, file_titles = extract_all_infos(args.dir)
import json

with open(args.output, 'w') as f:
json.dump(apis_dict, f, indent=4)
r = os.path.splitext(args.output)
with open('{}-titles{}'.format(r[0], r[1]), 'w') as f:
with open(f'{r[0]}-titles{r[1]}', 'w') as f:
json.dump(file_titles, f, indent=4)

print('Done')
24 changes: 10 additions & 14 deletions docs/api/gen_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ def gen_functions_args_str(node):
str_args_list.append('*')
for kwoarg, d in zip(node.args.kwonlyargs, node.args.kw_defaults):
if isinstance(d, ast.Constant):
str_args_list.append("{}={}".format(kwoarg.arg, d.value))
str_args_list.append(f"{kwoarg.arg}={d.value}")
elif isinstance(d, ast.Name):
str_args_list.append("{}={}".format(kwoarg.arg, d.id))
str_args_list.append(f"{kwoarg.arg}={d.id}")
if node.args.kwarg is not None:
str_args_list.append('**' + node.args.kwarg.arg)

Expand Down Expand Up @@ -440,7 +440,7 @@ def set_display_attr_of_apis():
break
if not display_yes:
api_info_dict[id_api]["display"] = False
logger.info("set {} display to False".format(id_api))
logger.info(f"set {id_api} display to False")


def check_module_in_black_list(module_name):
Expand Down Expand Up @@ -543,7 +543,7 @@ def set_api_sketch():
all_api_found = {}
for m, apis in alldict.items():
for api in apis:
all_api_found['{}.{}'.format(m, api)] = False
all_api_found[f'{m}.{api}'] = False

for api in all_api_found.keys():
for id_api in api_info_dict.keys():
Expand Down Expand Up @@ -653,7 +653,7 @@ def gen_en_files(api_label_file="api_label"):
):
continue
elif "display" in api_info and not api_info["display"]:
logger.debug("{} display False".format(id_api))
logger.debug(f"{id_api} display False")
continue
elif 'type' in api_info and api_info['type'] in [
'module',
Expand All @@ -672,9 +672,7 @@ def gen_en_files(api_label_file="api_label"):
):
continue
elif "doc_filename" not in api_info:
logger.debug(
"{} does not have doc_filename field.".format(id_api)
)
logger.debug(f"{id_api} does not have doc_filename field.")
continue
else:
logger.debug(api_info["doc_filename"])
Expand All @@ -687,7 +685,7 @@ def gen_en_files(api_label_file="api_label"):
gen = EnDocGenerator(api_info)
api_name, api_ref_name = gen()
if api_name and api_ref_name:
api_label.write("{}\t.. {}:\n".format(api_name, api_ref_name))
api_label.write(f"{api_name}\t.. {api_ref_name}:\n")


def check_cn_en_match(path="./paddle", diff_file="en_cn_files_diff"):
Expand Down Expand Up @@ -790,7 +788,7 @@ def _print_ref_(self):
"""
if self.api_name is None:
return
self.stream.write(".. {}:\n\n".format(self.api_ref_name))
self.stream.write(f".. {self.api_ref_name}:\n\n")

def _print_header_(self, name, dot, is_title):
"""
Expand Down Expand Up @@ -863,12 +861,10 @@ def print_function(self):
self._print_ref_()
self._print_header_(self.short_name, dot='-', is_title=False)
self.stream.write(
'''.. autofunction:: {}
f'''.. autofunction:: {self.api_name}
:noindex:
'''.format(
self.api_name
)
'''
)

def __call__(self):
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ ignore = [
# need to remove
"F541",
"I001",
"UP032",
"F401",
"W291",
"PLR1722",
Expand Down

0 comments on commit ca4b164

Please sign in to comment.