@@ -155,12 +155,13 @@ New Features
155155PEP 701: Syntactic formalization of f-strings
156156---------------------------------------------
157157
158- :pep: `701 ` lifts some restrictions on the usage of f-strings. Expression components
159- inside f-strings can now be any valid Python expression including backslashes,
160- unicode escaped sequences, multi-line expressions, comments and strings reusing the
161- same quote as the containing f-string. Let's cover these in detail:
158+ :pep: `701 ` lifts some restrictions on the usage of :term: `f-strings <f-string> `.
159+ Expression components inside f-strings can now be any valid Python expression,
160+ including strings reusing the same quote as the containing f-string,
161+ multi-line expressions, comments, backslashes, and unicode escape sequences.
162+ Let's cover these in detail:
162163
163- * Quote reuse: in Python 3.11, reusing the same quotes as the containing f-string
164+ * Quote reuse: in Python 3.11, reusing the same quotes as the enclosing f-string
164165 raises a :exc: `SyntaxError `, forcing the user to either use other available
165166 quotes (like using double quotes or triple quotes if the f-string uses single
166167 quotes). In Python 3.12, you can now do things like this:
@@ -183,11 +184,12 @@ same quote as the containing f-string. Let's cover these in detail:
183184 >>> f " { f " { f " { f " { f " { f " { 1 + 1 } " } " } " } " } " } "
184185 '2'
185186
186- * Multi-line expressions and comments: In Python 3.11, f-strings expressions
187- must be defined in a single line even if outside f-strings expressions could
188- span multiple lines (like literal lists being defined over multiple lines),
189- making them harder to read. In Python 3.12 you can now define expressions
190- spanning multiple lines and include comments on them:
187+ * Multi-line expressions and comments: In Python 3.11, f-string expressions
188+ must be defined in a single line, even if the expression within the f-string
189+ could normally span multiple lines
190+ (like literal lists being defined over multiple lines),
191+ making them harder to read. In Python 3.12 you can now define f-strings
192+ spanning multiple lines, and add inline comments:
191193
192194 >>> f " This is the playlist: { " , " .join([
193195 ... ' Take me back to Eden' , # My, my, those eyes like fire
@@ -197,10 +199,10 @@ same quote as the containing f-string. Let's cover these in detail:
197199 'This is the playlist: Take me back to Eden, Alkaline, Ascensionism'
198200
199201* Backslashes and unicode characters: before Python 3.12 f-string expressions
200- couldn't contain any ``\ `` character. This also affected unicode escaped
201- sequences (such as ``\N{snowman} ``) as these contain the `` \N `` part that
202- previously could not be part of expression components of f-strings. Now, you
203- can define expressions like this:
202+ couldn't contain any ``\ `` character. This also affected unicode :ref: ` escape
203+ sequences <escape-sequences>` (such as ``\N{snowman} ``) as these contain
204+ the `` \N `` part that previously could not be part of expression components of
205+ f-strings. Now, you can define expressions like this:
204206
205207 >>> print (f " This is the playlist: { " \n " .join(songs)} " )
206208 This is the playlist: Take me back to Eden
@@ -212,7 +214,7 @@ same quote as the containing f-string. Let's cover these in detail:
212214See :pep: `701 ` for more details.
213215
214216As a positive side-effect of how this feature has been implemented (by parsing f-strings
215- with the PEG parser (see :pep: ` 617 `) , now error messages for f-strings are more precise
217+ with :pep: ` the PEG parser < 617 >` , now error messages for f-strings are more precise
216218and include the exact location of the error. For example, in Python 3.11, the following
217219f-string raises a :exc: `SyntaxError `:
218220
0 commit comments