Skip to content

Commit f787eb8

Browse files
committed
Misc cleanup
1 parent e6e1f92 commit f787eb8

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

mypy/fastparse.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,14 +1734,18 @@ def visit_TemplateStr(self, n: ast_TemplateStr) -> Expression:
17341734
def visit_Interpolation(self, n: ast_Interpolation) -> Expression:
17351735
interp_cls = NameExpr("__mypy-Interpolation")
17361736
interp_cls.set_line(n.lineno, n.col_offset)
1737-
val_exp = self.visit(n.value)
1738-
val_exp.set_line(interp_cls)
1739-
val_str = StrExpr(n.str)
1737+
val_expr = self.visit(n.value)
1738+
val_expr.set_line(interp_cls)
1739+
str_expr = StrExpr(n.str)
1740+
str_expr.set_line(interp_cls)
17401741
conv_expr = NameExpr("None") if n.conversion < 0 else StrExpr(chr(n.conversion))
1741-
format_spec_exp = self.visit(n.format_spec) if n.format_spec is not None else StrExpr("")
1742+
conv_expr.set_line(interp_cls)
1743+
format_expr = self.visit(n.format_spec) if n.format_spec is not None else StrExpr("")
1744+
if format_expr.line == -1:
1745+
format_expr.set_line(interp_cls)
17421746
e = CallExpr(
17431747
interp_cls,
1744-
[val_exp, val_str, conv_expr, format_spec_exp],
1748+
[val_expr, str_expr, conv_expr, format_expr],
17451749
[ARG_POS, ARG_POS, ARG_POS, ARG_POS],
17461750
[None, None, None, None],
17471751
)

test-data/unit/parse-python314.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[case testTStringSimple]
1+
[case testTemplateStringSimple]
22
x = 'mypy'
33
t'Hello {x}'
44
[out]
@@ -20,7 +20,7 @@ MypyFile:1(
2020
NameExpr(None)
2121
StrExpr()))))))
2222

23-
[case testTStringWithConversion]
23+
[case testTemplateStringWithConversion]
2424
x = 'mypy'
2525
T'Hello {x!r}'
2626
[out]
@@ -42,7 +42,7 @@ MypyFile:1(
4242
StrExpr(r)
4343
StrExpr()))))))
4444

45-
[case testFStringWithOnlyFormatSpecifier]
45+
[case testTemplateStringWithOnlyFormatSpecifier]
4646
x = 'mypy'
4747
t'Hello {x:<30}'
4848
[out]
@@ -64,7 +64,7 @@ MypyFile:1(
6464
NameExpr(None)
6565
StrExpr(<30)))))))
6666

67-
[case testFStringWithFormatSpecifierAndConversion]
67+
[case testTemplateStringWithFormatSpecifierAndConversion]
6868
x = 'mypy'
6969
t'Hello {x!s:<30}'
7070
[out]
@@ -86,7 +86,7 @@ MypyFile:1(
8686
StrExpr(s)
8787
StrExpr(<30)))))))
8888

89-
[case testFStringWithFormatSpecifierExpression]
89+
[case testTemplateStringWithFormatSpecifierExpression]
9090
x = 'mypy'
9191
y = 30
9292
t'Hello {x!s:<{y+y}}'

0 commit comments

Comments
 (0)