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 emilyemorehouse
Recipients SilentGhost, barry, emilyemorehouse, eric.smith, larry, lukasz.langa, serhiy.storchaka, xtreak
Date 2019-05-05.15:42:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1557070959.61.0.398435818647.issue36798@roundup.psfhosted.org>
In-reply-to
Content
My initial reaction is that named expressions should not be valid in f-strings and should instead raise an exception, the same way that using `a := 10` does.

>>> a := 10
  File "<stdin>", line 1
    a := 10
      ^
SyntaxError: invalid syntax

It could be expected that named expressions could be used in f-strings in the same way as, say, list comprehensions or when used in parenthesis. One of the tricky things about named expressions is that the scope of the variable being assigned to gets "elevated" to the enclosing scope (this is a slightly simplified explanation but applies for most cases).

Since f-strings are executed when defined and not where they are used, this could lead to confusing behavior. Is it available only when defined? Would users expect a variable to be available again when the f-string if it were saved to a variable? Would we modify the expected behavior of named expressions to contain scope to only the f-string? I'm not sure that any of these are particularly clear in behavior or in the definitions laid out in PEP 572.
History
Date User Action Args
2019-05-05 15:42:39emilyemorehousesetrecipients: + emilyemorehouse, barry, larry, eric.smith, SilentGhost, lukasz.langa, serhiy.storchaka, xtreak
2019-05-05 15:42:39emilyemorehousesetmessageid: <1557070959.61.0.398435818647.issue36798@roundup.psfhosted.org>
2019-05-05 15:42:39emilyemorehouselinkissue36798 messages
2019-05-05 15:42:39emilyemorehousecreate