MCPcopy
hub / github.com/python/mypy / visit_JoinedStr

Method visit_JoinedStr

mypy/fastparse.py:1652–1671  ·  view source on GitHub ↗
(self, n: ast3.JoinedStr)

Source from the content-addressed store, hash-verified

1650
1651 # JoinedStr(expr* values)
1652 def visit_JoinedStr(self, n: ast3.JoinedStr) -> Expression:
1653 # Each of n.values is a str or FormattedValue; we just concatenate
1654 # them all using ''.join.
1655 empty_string = StrExpr("")
1656 empty_string.set_line(n.lineno, n.col_offset)
1657 strs_to_join = ListExpr(self.translate_expr_list(n.values))
1658 strs_to_join.set_line(empty_string)
1659 # Don't make unnecessary join call if there is only one str to join
1660 if len(strs_to_join.items) == 1:
1661 return self.set_line(strs_to_join.items[0], n)
1662 elif len(strs_to_join.items) > 1:
1663 last = strs_to_join.items[-1]
1664 if isinstance(last, StrExpr) and last.value == "":
1665 # 3.12 can add an empty literal at the end. Delete it for consistency
1666 # between Python versions.
1667 del strs_to_join.items[-1:]
1668 join_method = MemberExpr(empty_string, "join")
1669 join_method.set_line(empty_string)
1670 result_expression = CallExpr(join_method, [strs_to_join], [ARG_POS], [None])
1671 return self.set_line(result_expression, n)
1672
1673 # FormattedValue(expr value)
1674 def visit_FormattedValue(self, n: ast3.FormattedValue) -> Expression:

Callers

nothing calls this directly

Calls 8

set_lineMethod · 0.95
translate_expr_listMethod · 0.95
StrExprClass · 0.90
ListExprClass · 0.90
MemberExprClass · 0.90
CallExprClass · 0.90
lenFunction · 0.85
isinstanceFunction · 0.85

Tested by

no test coverage detected