Skip to content

Commit bec6cbe

Browse files
fix: improve f-strings even more (#10)
* fix: improve f-strings even more * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 79ce7d9 commit bec6cbe

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/unparser.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,10 +1035,18 @@ impl Unparser {
10351035

10361036
let has_single = escaped_source.contains("'");
10371037
let has_double = escaped_source.contains("\"");
1038-
let has_single_doc = escaped_source.contains("'''");
1039-
if has_single && has_double && has_single_doc {
1038+
1039+
if has_single
1040+
&& has_double
1041+
&& escaped_source.starts_with("\"")
1042+
&& escaped_source.ends_with("\"")
1043+
{
10401044
escaped_source = replace_first_and_last(&escaped_source, "\"\"\"")
1041-
} else if has_single && has_double {
1045+
} else if has_single
1046+
&& has_double
1047+
&& escaped_source.starts_with("'")
1048+
&& escaped_source.ends_with("'")
1049+
{
10421050
escaped_source = replace_first_and_last(&escaped_source, "'''")
10431051
} else if has_single {
10441052
escaped_source = replace_first_and_last(&escaped_source, "\"")

test_files/f_string.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
for (k, v) in attribs.items() # noqa
2020
)
2121
)
22+
23+
completion_init_lines = [f"source '{completion_path}'"] # noqa
24+
2225
# fmt: on

0 commit comments

Comments
 (0)