Skip to content

Commit 663a8f6

Browse files
authored
chore(internal): replace string concatenation with f-strings (#908)
1 parent bbb648e commit 663a8f6

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/openai/_utils/_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def human_join(seq: Sequence[str], *, delim: str = ", ", final: str = "or") -> s
230230

231231
def quote(string: str) -> str:
232232
"""Add single quotation marks around the given string. Does *not* do any escaping."""
233-
return "'" + string + "'"
233+
return f"'{string}'"
234234

235235

236236
def required_args(*variants: Sequence[str]) -> Callable[[CallableT], CallableT]:

src/openai/lib/_validators.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ def common_completion_prefix_validator(df: pd.DataFrame) -> Remediation:
309309
return Remediation(name="common_prefix")
310310

311311
def remove_common_prefix(x: Any, prefix: Any, ws_prefix: Any) -> Any:
312-
x["completion"] = x["completion"].str[len(prefix) :]
312+
x["completion"] = x["completion"].str[len(prefix):]
313313
if ws_prefix:
314314
# keep the single whitespace as prefix
315-
x["completion"] = " " + x["completion"]
315+
x["completion"] = f" {x['completion']}"
316316
return x
317317

318318
if (df.completion == common_prefix).all():
@@ -624,7 +624,7 @@ def get_outfnames(fname: str, split: bool) -> list[str]:
624624
while True:
625625
index_suffix = f" ({i})" if i > 0 else ""
626626
candidate_fnames = [
627-
os.path.splitext(fname)[0] + "_prepared" + suffix + index_suffix + ".jsonl" for suffix in suffixes
627+
f"{os.path.splitext(fname)[0]}_prepared{suffix}{index_suffix}.jsonl" for suffix in suffixes
628628
]
629629
if not any(os.path.isfile(f) for f in candidate_fnames):
630630
return candidate_fnames

tests/test_required_args.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def foo(*, a: str | None = None) -> str | None:
4343
def test_multiple_params() -> None:
4444
@required_args(["a", "b", "c"])
4545
def foo(a: str = "", *, b: str = "", c: str = "") -> str | None:
46-
return a + " " + b + " " + c
46+
return f"{a} {b} {c}"
4747

4848
assert foo(a="a", b="b", c="c") == "a b c"
4949

0 commit comments

Comments
 (0)