Skip to content

Commit

Permalink
Changed concatenation to f-strings (#2300)
Browse files Browse the repository at this point in the history
Summary:
Changed concatenation of strings to f-strings to avoid potential type's mismatch, simplify the code and unify it with others parts

Pull Request resolved: #2300

Reviewed By: mpolson64

Differential Revision: D55283388

Pulled By: Balandat

fbshipit-source-id: 5744ba6150ce5193440ed6c0a7580dc0570c12d4
  • Loading branch information
igeni authored and facebook-github-bot committed Mar 25, 2024
1 parent 3a701af commit 87bf0ca
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scripts/insert_api_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ def list_functions(source_glob):
node = ast.parse(open(sp).read())
# Extract the names of all functions and classes defined in this file
defined.extend(
(n.name, module_name + "." + n.name)
(n.name, f"{module_name}.{n.name}")
for n in node.body
if (isinstance(n, ast.FunctionDef) or isinstance(n, ast.ClassDef))
)
return defined


def replace_backticks(source_path, docs_path):
markdown_glob = docs_path + "/*.md"
source_glob = source_path + "/**/*.py"
markdown_glob = f"{docs_path}/*.md"
source_glob = f"{source_path}/**/*.py"
methods = list_functions(source_glob)
for f in glob.glob(markdown_glob):
for n, m in methods:
# Match backquoted mentions of the function/class name which are
# not already links
pattern = "(?<![[`])(`" + n + "`)"
pattern = f"(?<![[`])(`{n}`)"
link = f"[`{n}`](/api/{m.split('.')[1]}.html#{m})"
lines = open(f).readlines()
for i, l in enumerate(lines):
Expand Down

0 comments on commit 87bf0ca

Please sign in to comment.