This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author skreft
Recipients skreft
Date 2018-06-28.22:16:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1530224164.23.0.56676864532.issue33991@psf.upfronthosting.co.za>
In-reply-to
Content
Currently f-strings are parsed just as regular strings by lib2to3. However, this has the problem that the invariant of a string node being a literal is now broken.

This poses two problems. On one hand, if I want to compare that two string nodes are equivalent I would need to do something like:

def string_nodes_are_eqivalent(node1, node2):
  if is_f_string(node1) and is_f_string(node2):
    # This would require to parse the nodes using ast.parse
    return f_strings_are_equivalent(node1, node2)
  if not is_f_string(node1) and not is_f_string(node2):
    return ast.literal_eval(node1.value) == ast.literal_eval(node2.value)
  return False

Note that ast.literal_eval does not accept f-strings.
Also note that ast.parse returns an ast.JoinedString for f-strings, whose elements are either ast.Str or ast.FormattedValue, the latter being ast expressions.

On the other hand, this has the problem of not being able to refactor the expressions inside an f-string.
History
Date User Action Args
2018-06-28 22:16:04skreftsetrecipients: + skreft
2018-06-28 22:16:04skreftsetmessageid: <1530224164.23.0.56676864532.issue33991@psf.upfronthosting.co.za>
2018-06-28 22:16:04skreftlinkissue33991 messages
2018-06-28 22:16:03skreftcreate