Skip to content

Commit 2112398

Browse files
author
Adrien Chauve
committed
Add new f-string test to check expression type checking
1 parent 6c4aa78 commit 2112398

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mypy/fastparse.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,12 @@ def visit_Str(self, n: ast35.Str) -> Union[UnicodeExpr, StrExpr]:
776776
def visit_JoinedStr(self, n: ast35.JoinedStr) -> StrExpr:
777777
return StrExpr(n.values[0])
778778

779+
# FormattedValue(expr value)
780+
@with_line
781+
def visit_FormattedValue(self, n: ast35.FormattedValue) -> StrExpr:
782+
print(n, n.value, dir(n))
783+
return self.visit(n.value)
784+
779785
# Bytes(bytes s)
780786
@with_line
781787
def visit_Bytes(self, n: ast35.Bytes) -> Union[BytesExpr, StrExpr]:

test-data/unit/check-expressions.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,19 @@ u'%s' % (u'abc',)
11661166
# flags: --fast-parser
11671167
f'foobar'
11681168

1169+
[case testFStringTypecheckExpression]
1170+
# flags: --fast-parser
1171+
# flags: --python-version 3.6
1172+
a: str
1173+
a = 'foo'
1174+
b: str
1175+
b = f'{a}bar'
1176+
b == 'foobar'
1177+
f'{1 + "a"}'
1178+
f'{1 + 1}'
1179+
[out]
1180+
main:2: error: Unsupported operand types for + ("int" and "str")
1181+
11691182

11701183
-- Lambdas
11711184
-- -------

0 commit comments

Comments
 (0)