Skip to content

Commit 8ee27e3

Browse files
authored
gh-95913: Fix and copyedit New Features section of 3.11 What's New (GH-95915)
1 parent cbdeda8 commit 8ee27e3

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

Doc/c-api/code.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.. highlight:: c
22

3-
.. _codeobjects:
4-
53
.. index:: object; code, code object
64

5+
.. _codeobjects:
6+
77
Code Objects
88
------------
99

Doc/whatsnew/3.11.rst

+38-33
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ This article explains the new features in Python 3.11, compared to 3.10.
5050
For full details, see the :ref:`changelog <changelog>`.
5151

5252

53+
.. _whatsnew311-summary:
54+
5355
Summary -- Release highlights
5456
=============================
5557

@@ -96,16 +98,18 @@ Important deprecations, removals or restrictions:
9698
* :pep:`670`: Convert macros to functions in the Python C API.
9799

98100

101+
.. _whatsnew311-features:
102+
99103
New Features
100104
============
101105

102106
.. _whatsnew311-pep657:
103107

104-
Enhanced error locations in tracebacks
105-
--------------------------------------
108+
PEP 657: Enhanced error locations in tracebacks
109+
-----------------------------------------------
106110

107111
When printing tracebacks, the interpreter will now point to the exact expression
108-
that caused the error instead of just the line. For example:
112+
that caused the error, instead of just the line. For example:
109113

110114
.. code-block:: python
111115
@@ -118,9 +122,9 @@ that caused the error instead of just the line. For example:
118122
^^^^^^^^^
119123
AttributeError: 'NoneType' object has no attribute 'x'
120124
121-
Previous versions of the interpreter would point to just the line making it
125+
Previous versions of the interpreter would point to just the line, making it
122126
ambiguous which object was ``None``. These enhanced errors can also be helpful
123-
when dealing with deeply nested dictionary objects and multiple function calls,
127+
when dealing with deeply nested :class:`dict` objects and multiple function calls:
124128

125129
.. code-block:: python
126130
@@ -138,7 +142,7 @@ when dealing with deeply nested dictionary objects and multiple function calls,
138142
~~~~~~~~~~~~~~~~~~^^^^^
139143
TypeError: 'NoneType' object is not subscriptable
140144
141-
as well as complex arithmetic expressions:
145+
As well as complex arithmetic expressions:
142146

143147
.. code-block:: python
144148
@@ -148,33 +152,28 @@ as well as complex arithmetic expressions:
148152
~~~~~~^~~
149153
ZeroDivisionError: division by zero
150154
151-
See :pep:`657` for more details. (Contributed by Pablo Galindo, Batuhan Taskaya
152-
and Ammar Askar in :issue:`43950`.)
153-
154-
.. note::
155-
This feature requires storing column positions in code objects which may
156-
result in a small increase of disk usage of compiled Python files or
157-
interpreter memory usage. To avoid storing the extra information and/or
158-
deactivate printing the extra traceback information, the
159-
:option:`-X` ``no_debug_ranges`` command line flag or the :envvar:`PYTHONNODEBUGRANGES`
160-
environment variable can be used.
161-
162-
Column information for code objects
163-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164-
165-
The information used by the enhanced traceback feature is made available as a
166-
general API that can be used to correlate bytecode instructions with source
167-
code. This information can be retrieved using:
155+
Additionally, the information used by the enhanced traceback feature
156+
is made available via a general API, that can be used to correlate
157+
:term:`bytecode` :ref:`instructions <bytecodes>` with source code location.
158+
This information can be retrieved using:
168159

169160
- The :meth:`codeobject.co_positions` method in Python.
170-
- The :c:func:`PyCode_Addr2Location` function in the C-API.
171-
172-
The :option:`-X` ``no_debug_ranges`` option and the environment variable
173-
:envvar:`PYTHONNODEBUGRANGES` can be used to disable this feature.
161+
- The :c:func:`PyCode_Addr2Location` function in the C API.
174162

175163
See :pep:`657` for more details. (Contributed by Pablo Galindo, Batuhan Taskaya
176164
and Ammar Askar in :issue:`43950`.)
177165

166+
.. note::
167+
This feature requires storing column positions in :ref:`codeobjects`,
168+
which may result in a small increase in interpreter memory usage
169+
and disk usage for compiled Python files.
170+
To avoid storing the extra information
171+
and deactivate printing the extra traceback information,
172+
use the :option:`-X no_debug_ranges <-X>` command line option
173+
or the :envvar:`PYTHONNODEBUGRANGES` environment variable.
174+
175+
176+
.. _whatsnew311-pep654:
178177

179178
PEP 654: Exception Groups and ``except*``
180179
-----------------------------------------
@@ -192,14 +191,20 @@ See :pep:`654` for more details.
192191
Irit Katriel, Yury Selivanov and Guido van Rossum.)
193192

194193

194+
.. _whatsnew311-pep670:
195+
195196
PEP 678: Exceptions can be enriched with notes
196-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
197+
----------------------------------------------
198+
199+
The :meth:`~BaseException.add_note` method is added to :exc:`BaseException`.
200+
It can be used to enrich exceptions with context information
201+
that is not available at the time when the exception is raised.
202+
The added notes appear in the default traceback.
203+
204+
See :pep:`678` for more details.
197205

198-
The :meth:`add_note` method was added to :exc:`BaseException`. It can be
199-
used to enrich exceptions with context information which is not available
200-
at the time when the exception is raised. The notes added appear in the
201-
default traceback. See :pep:`678` for more details. (Contributed by
202-
Irit Katriel in :issue:`45607`.)
206+
(Contributed by Irit Katriel in :issue:`45607`.
207+
PEP written by Zac Hatfield-Dodds.)
203208

204209

205210
.. _new-feat-related-type-hints-311:

0 commit comments

Comments
 (0)