дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
feat(python): convert %-formatting and str.format() to f-strings (#5356)
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 <[email protected]>
Цей коміт міститься в:
1 джерело
2478f67066
коміт
cc1cc4cce5
5 files changed
+484
-1
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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}",
|
||||
|
||||
Reference in new issue
Заблокувати користувача