@@ -50,6 +50,8 @@ This article explains the new features in Python 3.11, compared to 3.10.
50
50
For full details, see the :ref: `changelog <changelog >`.
51
51
52
52
53
+ .. _whatsnew311-summary :
54
+
53
55
Summary -- Release highlights
54
56
=============================
55
57
@@ -96,16 +98,18 @@ Important deprecations, removals or restrictions:
96
98
* :pep: `670 `: Convert macros to functions in the Python C API.
97
99
98
100
101
+ .. _whatsnew311-features :
102
+
99
103
New Features
100
104
============
101
105
102
106
.. _whatsnew311-pep657 :
103
107
104
- Enhanced error locations in tracebacks
105
- --------------------------------------
108
+ PEP 657: Enhanced error locations in tracebacks
109
+ -----------------------------------------------
106
110
107
111
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:
109
113
110
114
.. code-block :: python
111
115
@@ -118,9 +122,9 @@ that caused the error instead of just the line. For example:
118
122
^^^^^^^^^
119
123
AttributeError : ' NoneType' object has no attribute ' x'
120
124
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
122
126
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:
124
128
125
129
.. code-block :: python
126
130
@@ -138,7 +142,7 @@ when dealing with deeply nested dictionary objects and multiple function calls,
138
142
~~~~~~~~~~~~~~~~~~^^^^^
139
143
TypeError : ' NoneType' object is not subscriptable
140
144
141
- as well as complex arithmetic expressions:
145
+ As well as complex arithmetic expressions:
142
146
143
147
.. code-block :: python
144
148
@@ -148,33 +152,28 @@ as well as complex arithmetic expressions:
148
152
~~~~~~^~~
149
153
ZeroDivisionError : division by zero
150
154
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:
168
159
169
160
- 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.
174
162
175
163
See :pep: `657 ` for more details. (Contributed by Pablo Galindo, Batuhan Taskaya
176
164
and Ammar Askar in :issue: `43950 `.)
177
165
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 :
178
177
179
178
PEP 654: Exception Groups and ``except* ``
180
179
-----------------------------------------
@@ -192,14 +191,20 @@ See :pep:`654` for more details.
192
191
Irit Katriel, Yury Selivanov and Guido van Rossum.)
193
192
194
193
194
+ .. _whatsnew311-pep670 :
195
+
195
196
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.
197
205
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.)
203
208
204
209
205
210
.. _new-feat-related-type-hints-311 :
0 commit comments