Skip to content

Commit

Permalink
Add new f-string test to check expression type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Chauve committed Dec 30, 2016
1 parent 6c4aa78 commit 2112398
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,12 @@ def visit_Str(self, n: ast35.Str) -> Union[UnicodeExpr, StrExpr]:
def visit_JoinedStr(self, n: ast35.JoinedStr) -> StrExpr:
return StrExpr(n.values[0])

# FormattedValue(expr value)
@with_line
def visit_FormattedValue(self, n: ast35.FormattedValue) -> StrExpr:
print(n, n.value, dir(n))
return self.visit(n.value)

# Bytes(bytes s)
@with_line
def visit_Bytes(self, n: ast35.Bytes) -> Union[BytesExpr, StrExpr]:
Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,19 @@ u'%s' % (u'abc',)
# flags: --fast-parser
f'foobar'

[case testFStringTypecheckExpression]
# flags: --fast-parser
# flags: --python-version 3.6
a: str
a = 'foo'
b: str
b = f'{a}bar'
b == 'foobar'
f'{1 + "a"}'
f'{1 + 1}'
[out]
main:2: error: Unsupported operand types for + ("int" and "str")


-- Lambdas
-- -------
Expand Down

0 comments on commit 2112398

Please sign in to comment.