From cc1cc4cce5f1ae6d606179bee2fbfc6ce045c8ee Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Tue, 24 Nov 2026 01:30:27 +0900 Subject: [PATCH] feat(python): convert %-formatting and str.format() to f-strings (#5356) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alt+Enter on a Python `%`-format expression said "No intentions available". It now offers PyCharm's **Convert to f-string literal** and **Replace with str.format() call**; on a `str.format()` call it offers **Convert to f-string literal**. Neither basedpyright nor Ruff offers these (Ruff's UP031/UP032 only report when a project enables pyupgrade rules, and the fix is not a quick fix). `%` conversions `s r a d i u f e g x o` with flags, widths and precisions map to the equivalent format specs (`%5s` → `{x!s:>5}`, `%-8.3e` → `{x:<8.3e}`); `%d` keeps its truncation as `{int(x)}` unless the value is an int literal or `len()`/`int()`/`ord()` (`%05d` % `len(a)` → `{len(a):05d}`); `%(key)s` works with a dict literal; `%%` and literal braces are escaped, and `\N{NAME}` escapes are kept as they are. `.format()` fields support auto and manual numbering, keywords, `.attr` / `[0]` accessors, `!r` and specs. The conversion is not offered when it could change behaviour or produce invalid code: bytes, `*`/`**` arguments, `%c`, `*` widths, a precision on an integer conversion, nested format specs, a wrong argument count, an argument that would be dropped or evaluated twice, an argument containing the string's quote, a backslash or `#` (f-strings before Python 3.12), or, for `.format()`, a key that is a Python keyword. As in PyCharm, a single `%` operand that is not a tuple literal is taken as one value. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- src/editor/lsp/semantic/python/index.ts | 3 +- .../lsp/semantic/python/stringFormat.test.ts | 118 ++++++ .../lsp/semantic/python/stringFormat.ts | 360 ++++++++++++++++++ src/platform/locales/text/en.json | 2 + src/platform/locales/text/zh.json | 2 + 5 files changed, 484 insertions(+), 1 deletion(-) create mode 100644 src/editor/lsp/semantic/python/stringFormat.test.ts create mode 100644 src/editor/lsp/semantic/python/stringFormat.ts diff --git a/src/editor/lsp/semantic/python/index.ts b/src/editor/lsp/semantic/python/index.ts index fd053e164..9d55a19e7 100644 --- a/src/editor/lsp/semantic/python/index.ts +++ b/src/editor/lsp/semantic/python/index.ts @@ -13,6 +13,7 @@ import { type PythonSymbolKind, } from "./highlight"; import { implementPythonAbstractMethods, pythonMemberIntentions } from "./members"; +import { pythonStringIntentions } from "./stringFormat"; /** Server tokens these kinds override: the kind's own classes replace the generic ones. */ const VARIABLE_KINDS = new Set([ @@ -52,7 +53,7 @@ const pythonSemantics: LanguageSemantics = { } }, isLocal: ({ type, kind }) => (kind ? kind === "localVariable" || kind === "parameter" : type === "parameter"), - intentions: pythonMemberIntentions, + intentions: (view) => [...pythonMemberIntentions(view), ...pythonStringIntentions(view)], implementMethods: implementPythonAbstractMethods, }; diff --git a/src/editor/lsp/semantic/python/stringFormat.test.ts b/src/editor/lsp/semantic/python/stringFormat.test.ts new file mode 100644 index 000000000..396938813 --- /dev/null +++ b/src/editor/lsp/semantic/python/stringFormat.test.ts @@ -0,0 +1,118 @@ +import { describe, expect, it } from "vitest"; +import { EditorState } from "@codemirror/state"; +import { completedSyntaxTree } from "@/test/syntax"; +import { findLanguageDescription, loadSupport } from "../../../core/cm/languages"; +import { stringConversions } from "./stringFormat"; + +/** `expr`'s conversions with the caret on its first character, by kind. */ +async function convert(expr: string): Promise> { + const support = await loadSupport(findLanguageDescription("Python", "demo.py")!); + const source = `x = ${expr}\n`; + const state = EditorState.create({ doc: source, extensions: [support!] }); + const found = stringConversions(completedSyntaxTree(state), state.doc, 4); + return Object.fromEntries(found.map((c) => [c.kind, c.text])); +} + +describe("Python string formatting conversions", () => { + it("converts %-formatting to an f-string and to str.format()", async () => { + expect(await convert(`"Hello %s, you are %d" % (name, age)`)).toEqual({ + fString: `f"Hello {name}, you are {int(age)}"`, + format: `"Hello {}, you are {}".format(name, int(age))`, + }); + expect(await convert(`'%s' % user.name`)).toEqual({ fString: `f'{user.name}'`, format: `'{}'.format(user.name)` }); + }); + + it("maps flags, widths, precisions and conversions", async () => { + expect((await convert(`"%5s|%-5s|%r|%.2f|%05d|%+x|%-8.3e|%%" % (a, b, c, d, e, f, g)`)).fString).toBe( + `f"{a!s:>5}|{b!s:<5}|{c!r}|{d:.2f}|{int(e):05d}|{f:+x}|{g:<8.3e}|%"`, + ); + }); + + it("supports a mapping with a dict literal and escapes braces", async () => { + expect(await convert(`"{%(n)s} %(m)r" % {"n": 1, 'm': x}`)).toEqual({ + fString: `f"{{{1}}} {x!r}"`, + format: `"{{{n}}} {m!r}".format(n=1, m=x)`, + }); + }); + + it("converts str.format() calls to f-strings", async () => { + expect((await convert(`"{} in {}".format(count, path)`)).fString).toBe(`f"{count} in {path}"`); + expect((await convert(`"{1}-{0}-{1}".format(a, b)`)).fString).toBe(`f"{b}-{a}-{b}"`); + expect((await convert(`"{name!r:>10} {{x}}".format(name=user.name)`)).fString).toBe(`f"{user.name!r:>10} {{x}}"`); + expect((await convert(`"{0.real} {1[0]}".format(a + b, items)`)).fString).toBe(`f"{(a + b).real} {items[0]}"`); + expect((await convert(`r'\\d{}'.format(n)`)).fString).toBe(`rf'\\d{n}'`); + expect((await convert(`u"{}".format({1: 2})`)).fString).toBe(`f"{ {1: 2}}"`); + }); + + it("offers nothing when the result could behave differently or be invalid", async () => { + for (const expr of [ + `b"%s" % x`, + `"%s %s" % (a,)`, + `"%s" % (*a,)`, + `"%c" % 65`, + `"%*d" % (3, 4)`, + `"%(a)s" % mapping`, + `"{}".format(*args)`, + `"{}".format(**kw)`, + `"{}".format(a, b)`, + `"{0}{0}".format(next(it))`, + `"{:{w}}".format(a, w=3)`, + `"{x[key]}".format(x=d)`, + `"{}".format(d["key"])`, + `"{}".format("\\n".join(lines))`, + ]) + expect(await convert(expr), expr).toEqual({}); + expect((await convert(`'{}'.format(d["key"])`)).fString).toBe(`f'{d["key"]}'`); + }); + + it("keeps %d's truncation with int() unless the value is an int already", async () => { + expect(await convert(`"%d%%" % (ratio * 100)`)).toEqual({ + fString: `f"{int(ratio * 100)}%"`, + format: `"{}%".format(int(ratio * 100))`, + }); + expect((await convert(`"%s of %d tasks, %i/%d" % (len(done), len(tasks), 3, int(x))`)).fString).toBe( + `f"{len(done)} of {len(tasks)} tasks, {3}/{int(x)}"`, + ); + expect(await convert(`"%(n)d is %(n)s" % {"n": x}`)).toEqual({ fString: `f"{int(x)} is {x}"` }); + }); + + it("leaves \\N{...} escapes alone, except in raw strings", async () => { + expect(await convert(`"\\N{BULLET} %s" % x`)).toEqual({ + fString: `f"\\N{BULLET} {x}"`, + format: `"\\N{BULLET} {}".format(x)`, + }); + expect((await convert(`"\\N{BULLET} {}".format(x)`)).fString).toBe(`f"\\N{BULLET} {x}"`); + expect((await convert(`"\\\\N{x} %s" % y`)).fString).toBe(`f"\\\\N{{x}} {y}"`); + expect((await convert(`r"\\N{x} %s" % y`)).fString).toBe(`rf"\\N{{x}} {y}"`); + }); + + it("declines integer precisions and keyword names in .format()", async () => { + expect(await convert(`"%.2d" % h`)).toEqual({}); + expect(await convert(`"%(class)s" % {"class": c}`)).toEqual({ fString: `f"{c}"` }); + }); + + it("does not rewrite format expressions with missing or inconsistent field references", async () => { + for (const expr of [ + `"%(name)s" % {"other": value}`, + `"%(name)s" % {}`, + `"{}{0}".format(a)`, + `"{0}{}".format(a, b)`, + `"{name}".format(name=)`, + ]) + expect(await convert(expr), expr).toEqual({}); + }); + + it("uses valid Python syntax for field accessors", async () => { + expect(await convert(`"{0[001]}".format(items)`)).toEqual({ fString: `f"{items[1]}"` }); + expect(await convert(`"{0.class}".format(obj)`)).toEqual({}); + }); + + it("keeps the order and evaluation count of arguments with side effects", async () => { + expect(await convert(`"{1}-{0}".format(first(), second())`)).toEqual({}); + expect(await convert(`"{b}-{a}".format(a=first(), b=second())`)).toEqual({}); + expect(await convert(`"%(name)s" % {"name": first(), "name": second()}`)).toEqual({}); + expect(await convert(`"%(b)s-%(a)s" % {"a": first(), "b": second()}`)).toEqual({ + format: `"{b}-{a}".format(a=first(), b=second())`, + }); + }); +}); diff --git a/src/editor/lsp/semantic/python/stringFormat.ts b/src/editor/lsp/semantic/python/stringFormat.ts new file mode 100644 index 000000000..a7753347c --- /dev/null +++ b/src/editor/lsp/semantic/python/stringFormat.ts @@ -0,0 +1,360 @@ +/** + * PyCharm's "Convert to f-string literal" and "Replace with str.format() call" + * on `%`-formatting and `str.format()` calls. A conversion that could change + * what the code does, or produce code an older Python rejects, is not offered. + * As in PyCharm, a single `%` operand that is not a tuple literal is taken as one + * value: a variable holding a tuple would format differently after conversion. + */ +import { syntaxTree } from "@codemirror/language"; +import type { Text } from "@codemirror/state"; +import type { EditorView } from "@codemirror/view"; +import type { SyntaxNode, Tree } from "@lezer/common"; +import type { ContributedIntention } from "@/editor/api"; +import { tx } from "@/platform/i18n"; +import { docOf } from "../../lsp"; + +export interface StringConversion { + kind: "fString" | "format"; + from: number; + to: number; + text: string; +} + +interface Field { + /** Auto-numbered (null), positional index or keyword. */ + key: number | string | null; + /** `.attr` / `[0]` accessors after the field name. */ + tail: string; + conv: string; + spec: string; + /** A `%d`/`%i`/`%u` field: `%` truncates a float with `int()`, a `d` format spec raises. */ + int?: boolean; +} +/** Literal text, already brace-escaped as it appears in the result. */ +type Part = string | Field; + +interface Arg { + text: string; + node: SyntaxNode | null; +} + +interface Literal { + prefix: string; + raw: boolean; + quote: string; + body: string; +} + +function literal(text: string): Literal | null { + const prefix = /^[A-Za-z]*/.exec(text)![0]; + if (/[bBfFtT]/.test(prefix)) return null; + const rest = text.slice(prefix.length); + const quote = rest.startsWith('"""') || rest.startsWith("'''") ? rest.slice(0, 3) : rest[0]!; + return { + prefix: prefix.replace(/[uU]/, ""), + raw: /[rR]/.test(prefix), + quote, + body: rest.slice(quote.length, rest.length - quote.length), + }; +} + +/** Comma-separated groups of `node`'s children, brackets dropped. */ +function groups(node: SyntaxNode): SyntaxNode[][] { + const out: SyntaxNode[][] = [[]]; + for (let c = node.firstChild; c; c = c.nextSibling) { + if (/^[([{]$|^[)\]}]$/.test(c.name)) continue; + if (c.name === ",") out.push([]); + else out[out.length - 1]!.push(c); + } + return out.filter((g) => g.length); +} + +const argOf = (doc: Text, g: SyntaxNode[]): Arg => ({ + text: doc.sliceString(g[0]!.from, g[g.length - 1]!.to), + node: g.length === 1 ? g[0]! : null, +}); + +const escapeBraces = (s: string) => s.replace(/[{}]/g, "$&$&"); + +/** Length of a `\\` or `\N{NAME}` escape at `i` of a non-raw literal; its braces are not fields. */ +function escapeLength(body: string, i: number): number { + if (body[i] !== "\\") return 0; + if (body[i + 1] === "\\") return 2; + if (body[i + 1] !== "N" || body[i + 2] !== "{") return 0; + const end = body.indexOf("}", i); + return end < 0 ? 0 : end + 1 - i; +} + +const PERCENT = /%(?:\((\w+)\))?([#0 +-]*)(\d+)?(?:\.(\d+))?[hlL]?([diouxXeEfFgGrsa%])/y; + +/** The fields of a `%` format string; null when a conversion has no f-string equivalent. */ +export function percentParts(body: string, raw = false): Part[] | null { + const parts: Part[] = []; + let text = ""; + for (let i = 0; i < body.length;) { + const escape = raw ? 0 : escapeLength(body, i); + if (escape) { + text += body.slice(i, i + escape); + i += escape; + continue; + } + if (body[i] !== "%") { + text += escapeBraces(body[i++]!); + continue; + } + PERCENT.lastIndex = i; + const m = PERCENT.exec(body); + if (!m) return null; + i = PERCENT.lastIndex; + const [all, key, flags = "", width = "", precision] = m; + const type = m[5]!; + if (type === "%") { + if (all !== "%%") return null; + text += "%"; + continue; + } + const prec = precision === undefined ? "" : `.${precision}`; + // An integer's `%` precision pads with zeros; a format spec rejects it. + if (prec && "diuoxX".includes(type)) return null; + const int = "diu".includes(type); + let conv = ""; + let spec: string; + if ("sra".includes(type)) { + conv = type === "s" && !width && !prec ? "" : `!${type}`; + spec = (width ? (flags.includes("-") ? "<" : ">") : "") + width + prec; + } else { + const align = flags.includes("-") ? "<" : ""; + const sign = flags.includes("+") ? "+" : flags.includes(" ") ? " " : ""; + const zero = flags.includes("0") && !align && width ? "0" : ""; + const rest = align + sign + (flags.includes("#") ? "#" : "") + zero + width + prec; + spec = int ? rest && `${rest}d` : rest + type; + } + parts.push(text, { key: key ?? null, tail: "", conv, spec: spec && `:${spec}`, ...(int && { int }) }); + text = ""; + } + parts.push(text); + return parts; +} + +const FIELD = /^(\d+|[A-Za-z_]\w*)?((?:\.[A-Za-z_]\w*|\[\d+\])*)(![rsa])?(:[^{}]*)?$/; + +/** The fields of a `str.format` string; null for nested or malformed fields. */ +export function formatParts(body: string, raw = false): Part[] | null { + const parts: Part[] = []; + let text = ""; + for (let i = 0; i < body.length;) { + const escape = raw ? 0 : escapeLength(body, i); + if (escape) { + text += body.slice(i, i + escape); + i += escape; + continue; + } + const c = body[i]!; + if ((c === "{" || c === "}") && body[i + 1] === c) { + text += c + c; + i += 2; + continue; + } + if (c === "}") return null; + if (c !== "{") { + text += c; + i++; + continue; + } + const end = body.indexOf("}", i); + const m = end < 0 ? null : FIELD.exec(body.slice(i + 1, end)); + if (!m) return null; + const [, name, tail = "", conv = "", spec = ""] = m; + parts.push(text, { key: name === undefined ? null : /^\d/.test(name) ? Number(name) : name, tail, conv, spec }); + text = ""; + i = end + 1; + } + parts.push(text); + return parts; +} + +/** An int literal, or `len()` / `int()` / `ord()`: `%d` of it needs no `int()`. */ +function isInt(arg: Arg): boolean { + const node = arg.node; + if (node?.name === "Number") return /^(?:\d[\d_]*|0[xob][\da-f_]+)$/i.test(arg.text); + const callee = node?.name === "CallExpression" ? node.firstChild : null; + return callee?.name === "VariableName" && /^(?:len|int|ord)\($/.test(arg.text.slice(0, callee.to - node!.from + 1)); +} + +/** The argument as a `%d` value: wrapped in `int()` unless it is one already. */ +function asInt(arg: Arg): Arg { + if (isInt(arg)) return arg; + const inner = arg.node?.name === "ParenthesizedExpression" ? arg.text.slice(1, -1) : arg.text; + return { text: "int(" + inner + ")", node: null }; +} + +const KEYWORDS = new Set( + "False None True and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield".split( + " ", + ), +); + +const ATOMIC = new Set(["VariableName", "MemberExpression", "CallExpression", "SubscriptExpression"]); + +/** `parts` with each field's argument inlined, or null if that is not safe. */ +function inline(parts: Part[], positional: Arg[], keyword: Map, quote: string): string | null { + const used = new Map(); + let next = 0; + let out = ""; + for (const part of parts) { + if (typeof part === "string") { + out += part; + continue; + } + if (part.key === null && next < 0) return null; + if (typeof part.key === "number") { + if (next > 0) return null; + next = -1; + } + const arg = + part.key === null + ? positional[next++] + : typeof part.key === "number" + ? positional[part.key] + : keyword.get(part.key); + if (!arg) return null; + used.set(arg, (used.get(arg) ?? 0) + 1); + const value = part.int ? asInt(arg) : arg; + const text = value.text; + // Before Python 3.12 an f-string field cannot hold its quote, a backslash or a comment. + if (text.includes("\\") || text.includes("#") || text.includes(quote[0]!)) return null; + if (text.includes("\n") && quote.length === 1) return null; + const bare = value !== arg || (arg.node && arg.node.name !== "LambdaExpression" && !text.includes(":=")); + let expr = bare ? text : `(${text})`; + if (part.tail) { + if ([...part.tail.matchAll(/\.(\w+)/g)].some(([, attr]) => KEYWORDS.has(attr!))) return null; + const accessors = part.tail.replace(/\[0+(?=\d)/g, "["); + expr = (arg.node && ATOMIC.has(arg.node.name) ? expr : `(${text})`) + accessors; + } + if (expr.startsWith("{")) expr = ` ${expr}`; + out += `{${expr}${part.conv}${part.spec}}`; + } + const all = [...positional, ...keyword.values()]; + // Every argument is evaluated once by the call: unused or repeated side effects would change. + for (const arg of all) { + const n = used.get(arg) ?? 0; + if (n === 0 || (n > 1 && arg.node?.name !== "VariableName")) return null; + } + // A call or dict evaluates arguments in source order. Inlining follows field order. + if (all.some((arg) => arg.node?.name !== "VariableName") && [...used.keys()].some((arg, i) => arg !== all[i])) + return null; + return out; +} + +/** The `%` operands: positional arguments, or the entries of a dict literal. */ +function percentArgs(doc: Text, rhs: SyntaxNode): { positional: Arg[]; keyword: Map } | null { + const keyword = new Map(); + if (rhs.name === "TupleExpression") { + const items = groups(rhs); + if (items.some((g) => g[0]!.name === "*")) return null; + return { positional: items.map((g) => argOf(doc, g)), keyword }; + } + if (rhs.name === "DictionaryExpression") { + for (const g of groups(rhs)) { + const [key, colon, ...value] = g; + if (key?.name !== "String" || colon?.name !== ":" || !value.length) return null; + const k = /^["']([A-Za-z_]\w*)["']$/.exec(doc.sliceString(key.from, key.to)); + if (!k || keyword.has(k[1]!)) return null; + keyword.set(k[1]!, argOf(doc, value)); + } + return { positional: [], keyword }; + } + return { positional: [{ text: doc.sliceString(rhs.from, rhs.to), node: rhs }], keyword }; +} + +function percentConversions(doc: Text, node: SyntaxNode): StringConversion[] { + const [str, op, rhs] = [node.firstChild, node.firstChild?.nextSibling, node.lastChild]; + if (str?.name !== "String" || op?.name !== "ArithOp" || doc.sliceString(op.from, op.to) !== "%" || !rhs) return []; + const lit = literal(doc.sliceString(str.from, str.to)); + const parts = lit && percentParts(lit.body, lit.raw); + const args = rhs && percentArgs(doc, rhs); + if (!lit || !parts || !args) return []; + const fields = parts.filter((p): p is Field => typeof p !== "string"); + const named = fields.every((f) => f.key !== null); + if (named) { + if (args.positional.length || fields.some((f) => typeof f.key !== "string" || !args.keyword.has(f.key))) return []; + } else if (args.keyword.size || fields.length !== args.positional.length || fields.some((f) => f.key !== null)) { + return []; + } + const out: StringConversion[] = []; + const inlined = inline(parts, args.positional, args.keyword, lit.quote); + if (inlined !== null) + out.push({ + kind: "fString", + from: node.from, + to: node.to, + text: `${lit.prefix}f${lit.quote}${inlined}${lit.quote}`, + }); + const body = parts.map((p) => (typeof p === "string" ? p : `{${p.key ?? ""}${p.conv}${p.spec}}`)).join(""); + // `.format(k=…)` needs keys that are not keywords, and a key used as `%d` and as text cannot be both. + const intKeys = new Set(fields.filter((f) => f.int).map((f) => f.key)); + const mixed = fields.some((f) => !f.int && intKeys.has(f.key)); + if (named && (mixed || [...args.keyword.keys()].some((k) => KEYWORDS.has(k)))) return out; + const callArgs = named + ? [...args.keyword].map(([k, v]) => `${k}=${(intKeys.has(k) ? asInt(v) : v).text}`) + : args.positional.map((a, i) => (fields[i]!.int ? asInt(a) : a).text); + out.push({ + kind: "format", + from: node.from, + to: node.to, + text: `${lit.prefix}${lit.quote}${body}${lit.quote}.format(${callArgs.join(", ")})`, + }); + return out; +} + +function formatConversion(doc: Text, call: SyntaxNode): StringConversion[] { + const member = call.firstChild; + const str = member?.firstChild; + const name = member?.lastChild; + const argList = call.getChild("ArgList"); + if (member?.name !== "MemberExpression" || str?.name !== "String" || name?.name !== "PropertyName" || !argList) + return []; + if (doc.sliceString(name.from, name.to) !== "format") return []; + const lit = literal(doc.sliceString(str.from, str.to)); + const parts = lit && formatParts(lit.body, lit.raw); + if (!lit || !parts) return []; + const positional: Arg[] = []; + const keyword = new Map(); + for (const g of groups(argList)) { + if (g[0]!.name === "*" || g[0]!.name === "**" || g.some((node) => node.type.isError)) return []; + if (g[1]?.name === "AssignOp") { + const key = doc.sliceString(g[0]!.from, g[0]!.to); + if (!g[2] || keyword.has(key)) return []; + keyword.set(key, argOf(doc, g.slice(2))); + } else positional.push(argOf(doc, g)); + } + const inlined = inline(parts, positional, keyword, lit.quote); + return inlined === null + ? [] + : [{ kind: "fString", from: call.from, to: call.to, text: `${lit.prefix}f${lit.quote}${inlined}${lit.quote}` }]; +} + +/** Conversions of the `%` expression or `.format()` call around `pos`, innermost first. */ +export function stringConversions(tree: Tree, doc: Text, pos: number): StringConversion[] { + for (let n: SyntaxNode | null = tree.resolveInner(pos, 1); n; n = n.parent) { + if (n.name === "BinaryExpression") { + const found = percentConversions(doc, n); + if (found.length) return found; + } else if (n.name === "CallExpression") { + const found = formatConversion(doc, n); + if (found.length) return found; + } else if (/Statement$|^Body$|^Script$/.test(n.name)) break; + } + return []; +} + +export function pythonStringIntentions(view: EditorView): ContributedIntention[] { + if (docOf(view)?.uiMode !== "Python" || !view.state.selection.main.empty) return []; + return stringConversions(syntaxTree(view.state), view.state.doc, view.state.selection.main.head).map((c) => ({ + id: `python.${c.kind}`, + label: c.kind === "fString" ? tx("Convert to f-string literal") : tx("Replace with str.format() call"), + icon: "bulb", + run: () => + view.dispatch({ changes: { from: c.from, to: c.to, insert: c.text }, userEvent: "input", scrollIntoView: true }), + })); +} diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 6d99242af..a4e642aca 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -3692,6 +3692,8 @@ "Installing package requirements": "Installing package requirements", "Cannot install package requirements": "Cannot install package requirements", "Install requirement": "Install requirement", + "Convert to f-string literal": "Convert to f-string literal", + "Replace with str.format() call": "Replace with str.format() call", "Install all missing requirements": "Install all missing requirements", "Package {name} is not installed": "Package {name} is not installed", "Requirement {requirement} is not satisfied: {installed} is installed": "Requirement {requirement} is not satisfied: {installed} is installed", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 65f7af107..9afd9072e 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -9931,6 +9931,8 @@ "Installing package requirements": "正在安装依赖包", "Cannot install package requirements": "无法安装依赖包", "Install requirement": "安装此依赖", + "Convert to f-string literal": "转换为 f-string 字面量", + "Replace with str.format() call": "替换为 str.format() 调用", "Install all missing requirements": "安装所有缺失的依赖", "Package {name} is not installed": "未安装软件包 {name}", "Requirement {requirement} is not satisfied: {installed} is installed": "未满足依赖 {requirement}:已安装 {installed}",