mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-138774: use value to ast.unparse code when str is None in ast.Interpolation (#139415)
This commit is contained in:
parent
6be6f8ff59
commit
4d0849426f
4 changed files with 102 additions and 12 deletions
|
|
@ -658,9 +658,9 @@ def _unparse_interpolation_value(self, inner):
|
|||
unparser.set_precedence(_Precedence.TEST.next(), inner)
|
||||
return unparser.visit(inner)
|
||||
|
||||
def _write_interpolation(self, node, is_interpolation=False):
|
||||
def _write_interpolation(self, node, use_str_attr=False):
|
||||
with self.delimit("{", "}"):
|
||||
if is_interpolation:
|
||||
if use_str_attr:
|
||||
expr = node.str
|
||||
else:
|
||||
expr = self._unparse_interpolation_value(node.value)
|
||||
|
|
@ -678,7 +678,8 @@ def visit_FormattedValue(self, node):
|
|||
self._write_interpolation(node)
|
||||
|
||||
def visit_Interpolation(self, node):
|
||||
self._write_interpolation(node, is_interpolation=True)
|
||||
# If `str` is set to `None`, use the `value` to generate the source code.
|
||||
self._write_interpolation(node, use_str_attr=node.str is not None)
|
||||
|
||||
def visit_Name(self, node):
|
||||
self.write(node.id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue