From d0e8c28ea824d35c216d01ef4d01f7692da64bd2 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Fri, 12 Aug 2022 00:21:57 -0500 Subject: [PATCH 1/5] 3.11 Whatsnew: Revise desc of enhanced error locations feature --- Doc/whatsnew/3.11.rst | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index f1f023038abe1c..576c9575346e42 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -102,11 +102,11 @@ New Features .. _whatsnew311-pep657: -Enhanced error locations in tracebacks --------------------------------------- +PEP 657: Enhanced error locations in tracebacks +----------------------------------------------- When printing tracebacks, the interpreter will now point to the exact expression -that caused the error instead of just the line. For example: +that caused the error, instead of just the line. For example: .. code-block:: python @@ -119,9 +119,9 @@ that caused the error instead of just the line. For example: ^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'x' -Previous versions of the interpreter would point to just the line making it +Previous versions of the interpreter would point to just the line, making it ambiguous which object was ``None``. These enhanced errors can also be helpful -when dealing with deeply nested dictionary objects and multiple function calls, +when dealing with deeply nested :class:`dict` objects and multiple function calls: .. code-block:: python @@ -139,7 +139,7 @@ when dealing with deeply nested dictionary objects and multiple function calls, ~~~~~~~~~~~~~~~~~~^^^^^ TypeError: 'NoneType' object is not subscriptable -as well as complex arithmetic expressions: +As well as complex arithmetic expressions: .. code-block:: python @@ -153,12 +153,14 @@ See :pep:`657` for more details. (Contributed by Pablo Galindo, Batuhan Taskaya and Ammar Askar in :issue:`43950`.) .. note:: - This feature requires storing column positions in code objects which may - result in a small increase of disk usage of compiled Python files or - interpreter memory usage. To avoid storing the extra information and/or - deactivate printing the extra traceback information, the - :option:`-X` ``no_debug_ranges`` command line flag or the :envvar:`PYTHONNODEBUGRANGES` - environment variable can be used. + This feature requires storing column positions in :ref:`codeobjects`, + which may result in a small increase in interpreter memory usage + and disk usage for compiled Python files. + To avoid storing the extra information + and deactivate printing the extra traceback information, + use the :option:`-X no_debug_ranges <-X>` command line option + or the :envvar:`PYTHONNODEBUGRANGES` environment variable. + Column information for code objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 7dacbbfea7a699eb243e5cbde96878f55f795704 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Fri, 12 Aug 2022 00:32:54 -0500 Subject: [PATCH 2/5] 3.11 Whatsnew: Combine error locations sections to avoid duplication --- Doc/c-api/code.rst | 4 ++-- Doc/whatsnew/3.11.rst | 25 ++++++++----------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/Doc/c-api/code.rst b/Doc/c-api/code.rst index d4a3c4ae35fa09..9054e7ee3181a5 100644 --- a/Doc/c-api/code.rst +++ b/Doc/c-api/code.rst @@ -1,9 +1,9 @@ .. highlight:: c -.. _codeobjects: - .. index:: object; code, code object +.. _codeobjects: + Code Objects ------------ diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 576c9575346e42..21a69bffc86e11 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -149,6 +149,14 @@ As well as complex arithmetic expressions: ~~~~~~^~~ ZeroDivisionError: division by zero +Additionally, the information used by the enhanced traceback feature +is made available via a general API, that can be used to correlate +:term:`bytecode` :ref:`instructions ` with source code location. +This information can be retrieved using: + +- The :meth:`codeobject.co_positions` method in Python. +- The :c:func:`PyCode_Addr2Location` function in the C API. + See :pep:`657` for more details. (Contributed by Pablo Galindo, Batuhan Taskaya and Ammar Askar in :issue:`43950`.) @@ -162,23 +170,6 @@ and Ammar Askar in :issue:`43950`.) or the :envvar:`PYTHONNODEBUGRANGES` environment variable. -Column information for code objects -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The information used by the enhanced traceback feature is made available as a -general API that can be used to correlate bytecode instructions with source -code. This information can be retrieved using: - -- The :meth:`codeobject.co_positions` method in Python. -- The :c:func:`PyCode_Addr2Location` function in the C-API. - -The :option:`-X` ``no_debug_ranges`` option and the environment variable -:envvar:`PYTHONNODEBUGRANGES` can be used to disable this feature. - -See :pep:`657` for more details. (Contributed by Pablo Galindo, Batuhan Taskaya -and Ammar Askar in :issue:`43950`.) - - PEP 654: Exception Groups and ``except*`` ----------------------------------------- From 548e6c78b8c2ad44f9f8d4d0ee514e4f72b13c6a Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Fri, 12 Aug 2022 00:33:54 -0500 Subject: [PATCH 3/5] 3.11 Whatsnew: Copyedit section describing exception notes --- Doc/whatsnew/3.11.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 21a69bffc86e11..54009609d2f972 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -187,13 +187,14 @@ Irit Katriel, Yury Selivanov and Guido van Rossum.) PEP 678: Exceptions can be enriched with notes -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The :meth:`add_note` method was added to :exc:`BaseException`. It can be -used to enrich exceptions with context information which is not available -at the time when the exception is raised. The notes added appear in the -default traceback. See :pep:`678` for more details. (Contributed by -Irit Katriel in :issue:`45607`.) +---------------------------------------------- + +The :meth:`~BaseException.add_note` method is added to :exc:`BaseException`. +It can be used to enrich exceptions with context information +that is not available at the time when the exception is raised. +The added notes appear in the default traceback. +See :pep:`678` for more details. +(Contributed by Irit Katriel in :issue:`45607`.) .. _new-feat-related-type-hints-311: From 81add60f11826093bd12de045b203b04e15f8c66 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Sat, 13 Aug 2022 12:52:48 +0100 Subject: [PATCH 4/5] gh-95914: Add to What's New a credit for PEP 678 author --- Doc/whatsnew/3.11.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 54009609d2f972..5a9e51a1e8dada 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -193,8 +193,11 @@ The :meth:`~BaseException.add_note` method is added to :exc:`BaseException`. It can be used to enrich exceptions with context information that is not available at the time when the exception is raised. The added notes appear in the default traceback. + See :pep:`678` for more details. -(Contributed by Irit Katriel in :issue:`45607`.) + +(Contributed by Irit Katriel in :issue:`45607`. +PEP written by Zac Hatfield-Dodds.) .. _new-feat-related-type-hints-311: From 3c4a03ac937cd515654736f5ac7a176ef264ec56 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Sun, 14 Aug 2022 02:34:05 -0500 Subject: [PATCH 5/5] Add standardized ref links to sections --- Doc/whatsnew/3.11.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 5a9e51a1e8dada..81822536f6ea8d 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -50,6 +50,8 @@ This article explains the new features in Python 3.11, compared to 3.10. For full details, see the :ref:`changelog `. +.. _whatsnew311-summary: + Summary -- Release highlights ============================= @@ -97,6 +99,8 @@ Important deprecations, removals or restrictions: * :pep:`670`: Convert macros to functions in the Python C API. +.. _whatsnew311-features: + New Features ============ @@ -170,6 +174,8 @@ and Ammar Askar in :issue:`43950`.) or the :envvar:`PYTHONNODEBUGRANGES` environment variable. +.. _whatsnew311-pep654: + PEP 654: Exception Groups and ``except*`` ----------------------------------------- @@ -186,6 +192,8 @@ See :pep:`654` for more details. Irit Katriel, Yury Selivanov and Guido van Rossum.) +.. _whatsnew311-pep670: + PEP 678: Exceptions can be enriched with notes ----------------------------------------------