Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd7a02f

Browse files
author
Kevin Kirsche
authored
refactor: prefer f-strings to other format/concatentation styles (#8474)
1 parent 38c4a1e commit bd7a02f

5 files changed

Lines changed: 7 additions & 7 deletions

File tree

scripts/create_baseline_stubs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def copy_stubs(src_base_dir: str, package: str, stub_dir: str) -> None:
5959
if os.path.isdir(src_dir):
6060
shutil.copytree(src_dir, os.path.join(stub_dir, package))
6161
else:
62-
src_file = os.path.join("out", package + ".pyi")
62+
src_file = os.path.join("out", f"{package}.pyi")
6363
if not os.path.isfile(src_file):
6464
sys.exit("Error: Cannot find generated stubs")
6565
shutil.copy(src_file, stub_dir)

scripts/stubsabot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ async def package_contains_py_typed(release_to_download: dict[str, Any], session
148148

149149

150150
def _check_spec(updated_spec: str, version: packaging.version.Version) -> str:
151-
assert version in packaging.specifiers.SpecifierSet("==" + updated_spec), f"{version} not in {updated_spec}"
151+
assert version in packaging.specifiers.SpecifierSet(f"=={updated_spec}"), f"{version} not in {updated_spec}"
152152
return updated_spec
153153

154154

@@ -183,7 +183,7 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U
183183
return NoUpdate(stub_info.distribution, "no longer updated")
184184

185185
pypi_info = await fetch_pypi_info(stub_info.distribution, session)
186-
spec = packaging.specifiers.SpecifierSet("==" + stub_info.version_spec)
186+
spec = packaging.specifiers.SpecifierSet(f"=={stub_info.version_spec}")
187187
if pypi_info.version in spec:
188188
return NoUpdate(stub_info.distribution, "up to date")
189189

tests/mypy_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def parse_versions(fname: StrPath) -> dict[str, tuple[MinVersion, MaxVersion]]:
147147
if line == "":
148148
continue
149149
m = _VERSION_LINE_RE.match(line)
150-
assert m, "invalid VERSIONS line: " + line
150+
assert m, f"invalid VERSIONS line: {line}"
151151
mod: str = m.group(1)
152152
min_version = parse_version(m.group(2))
153153
max_version = parse_version(m.group(3)) if m.group(3) else (99, 99)
@@ -160,7 +160,7 @@ def parse_versions(fname: StrPath) -> dict[str, tuple[MinVersion, MaxVersion]]:
160160

161161
def parse_version(v_str: str) -> tuple[int, int]:
162162
m = _VERSION_RE.match(v_str)
163-
assert m, "invalid version: " + v_str
163+
assert m, f"invalid version: {v_str}"
164164
return int(m.group(1)), int(m.group(2))
165165

166166

tests/pyright_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def main() -> None:
2727
print("error running npx; is Node.js installed?", file=sys.stderr)
2828
sys.exit(1)
2929

30-
command = [npx, "-p", "pyright@" + _PYRIGHT_VERSION, "pyright"] + sys.argv[1:]
30+
command = [npx, "-p", f"pyright@{_PYRIGHT_VERSION}", "pyright"] + sys.argv[1:]
3131

3232
ret = subprocess.run(command).returncode
3333
sys.exit(ret)

tests/stubtest_stdlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def run_stubtest(typeshed_dir: Path) -> int:
4646
"\nNB: stubtest output depends on the Python version (and system) it is run with. "
4747
"See README.md for more details.\n"
4848
"NB: We only check positional-only arg accuracy for Python 3.10.\n"
49-
"\nCommand run was: {}\n".format(" ".join(cmd)),
49+
f"\nCommand run was: {' '.join(cmd)}\n",
5050
file=sys.stderr,
5151
)
5252
print("\n\n", file=sys.stderr)

0 commit comments

Comments
 (0)