8000 gh-102856: Add changes related to PEP 701 in 3.12 What's New docs by mgmacias95 · Pull Request #104824 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-102856: Add changes related to PEP 701 in 3.12 What's New docs #104824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
  • Loading branch information
pablogsal and JelleZijlstra authored May 24, 2023
commit 93a9286c1092fb73565d113322cfcbf0648cee98
16 changes: 8 additions & 8 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ inside f-strings can now be any valid Python expression including backslashes,
unicode escaped sequences, multi-line expressions, comments and strings reusing the
same quote as the containing f-string. Let's cover these in detail:

* Quote reuse: in Python 3.11, reusing the same quotes as the contaning f-string
* Quote reuse: in Python 3.11, reusing the same quotes as the containing f-string
raises a :exc:`SyntaxError`, forcing the user to either use other available
quotes (like using double quotes or triple quites if the f-string uses single
quites). In Python 3.12, you can now do things like this:
quotes (like using double quotes or triple quotes if the f-string uses single
quotes). In Python 3.12, you can now do things like this:

>>> songs = ['Take me back to Eden', 'Alkaline', 'Ascensionism']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good improvement.

>>> f"This is the playlist: {", ".join(songs)}"
Expand All @@ -158,7 +158,7 @@ same quote as the containing f-string. Let's cover these in detail:
Note that before this change there was no explicit limit in how f-strings can
be nested, but the fact that string quotes cannot be reused inside the
expression component of f-strings made it impossible to nest f-strings
arbitrarily. In fact, this is the most nested-fstring that can be written:
arbitrarily. In fact, this is the most nested f-string that could be written:

>>> f"""{f'''{f'{f"{1+1}"}'}'''}"""
'2'
Expand Down Expand Up @@ -1280,10 +1280,10 @@ Changes in the Python API

* The output of the :func:`tokenize.tokenize` and :func:`tokenize.generate_tokens`
functions is now changed due to the changes introduced in :pep:`701`. This
means that ``STRING`` tokens are not emited anymore for f-strings and the
means that ``STRING`` tokens are not emitted any more for f-strings and the
tokens described in :pep:`701` are now produced instead: ``FSTRING_START``,
``FSRING_MIDDLE`` and ``FSTRING_END`` are now emited for f-string "string"
parts in addition to the the apropiate tokens for the tokenization in the
``FSRING_MIDDLE`` and ``FSTRING_END`` are now emitted for f-string "string"
parts in addition to the appropriate tokens for the tokenization in the
expression components. For example for the f-string ``f"start {1+1} end"``
the old version of the tokenizer emitted::

Expand All @@ -1301,7 +1301,7 @@ Changes in the Python API
1,13-1,17: FSTRING_MIDDLE ' end'
1,17-1,18: FSTRING_END '"'

Aditionally, final ``DEDENT`` tokens are now emited within the bounds of the
Aditionally, final ``DEDENT`` tokens are now emitted within the bounds of the
input. This means that for a file containing 3 lines, the old version of the
tokenizer returned a ``DEDENT`` token in line 4 whilst the new version returns
the token in line 3.
Expand Down
0