@@ -115,15 +115,16 @@ includes a note of the minimal failing example::
115
115
Non-goals
116
116
---------
117
117
``__note__ `` is *not * intended to carry structured data. If your note is for
118
- use by a program rather than display to a human, we recommend instead (or
119
- additionally) choosing a convention for an attribute like e.g.
120
- ``err._parse_errors = ... `` on the error or ``ExceptionGroup `` [1 ]_ [2 ]_
118
+ use by a program rather than display to a human, `we recommend
119
+ <https://discuss.python.org/t/accepting-pep-654-exception-groups-and-except/10813/26> `__
120
+ instead (or additionally) choosing a convention for an attribute, e.g.
121
+ ``err._parse_errors = ... `` on the error or ``ExceptionGroup ``.
121
122
122
123
As a rule of thumb, prefer `exception chaining
123
124
<https://docs.python.org/3/tutorial/errors.html#exception-chaining> `__ when the
124
125
error is going to be re-raised or handled as an individual error, and prefer
125
126
``__note__ `` when you are collecting multiple exception objects to handle
126
- together or later. [3 ]_
127
+ together or later. [1 ]_
127
128
128
129
129
130
Specification
@@ -149,8 +150,9 @@ Backwards Compatibility
149
150
=======================
150
151
151
152
System-defined or "dunder" names (following the pattern ``__*__ ``) are part of
152
- the language specification, with unassigned names reserved for future use and
153
- subject to breakage without warning [4 ]_.
153
+ the language specification, with `unassigned names reserved for future use and
154
+ subject to breakage without warning
155
+ <https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers> `__.
154
156
155
157
We are also unaware of any code which *would * be broken by adding ``__note__ ``;
156
158
assigning to a ``.__note__ `` attribute already *works * on current versions of
@@ -163,16 +165,15 @@ How to Teach This
163
165
=================
164
166
165
167
The ``__note__ `` attribute will be documented as part of the language standard,
166
- and explained as part of the tutorial "Errors and Exceptions" [ 5 ]_.
167
-
168
+ and explained as part of ` the "Errors and Exceptions" tutorial
169
+ <https://github.com/python/cpython/pull/30441> `__.
168
170
169
171
170
172
Reference Implementation
171
173
========================
172
174
173
- ``BaseException.__note__ `` was implemented in [6 ]_ and released in CPython
174
- 3.11.0a3, following discussions related to :pep: `654 `. [7 ]_ [8 ]_ [9 ]_
175
-
175
+ ``BaseException.__note__ `` was `implemented in <https://github.com/python/cpython/pull/29880 >`__ and released in CPython
176
+ 3.11.0a3, following discussions related to :pep: `654 `. [2 ]_
176
177
177
178
178
179
Rejected Ideas
@@ -204,8 +205,9 @@ for downstream code. We consider *always* raising a ``Wrapper`` exception
204
205
unacceptably inelegant; but because custom exception types might have any
205
206
number of required arguments we can't always create an instance of the *same *
206
207
type with our explanation. In cases where the exact exception type is known
207
- this can work, such as the standard library ``http.client `` code [10 ]_, but not
208
- for libraries which call user code.
208
+ this can work, such as the standard library ``http.client `` `code
209
+ <https://github.com/python/cpython/blob/69ef1b59983065ddb0b712dac3b04107c5059735/Lib/http/client.py#L596-L597> `__,
210
+ but not for libraries which call user code.
209
211
210
212
Second, exception chaining reports several lines of additional detail, which
211
213
are distracting for experienced users and can be very confusing for beginners.
@@ -297,9 +299,11 @@ formatted for display after propagation.
297
299
298
300
Add a helper function ``contextlib.add_exc_note() ``
299
301
---------------------------------------------------
300
- It was suggested [11 ]_ that we add a utility such as the one below to the
301
- standard library. We are open to this idea, but do not see it as a core part of
302
- the proposal of this PEP as it can be added as an enhancement later.
302
+ It `was suggested
303
+ <https://www.reddit.com/r/Python/comments/rmrvxv/pep_678_enriching_exceptions_with_notes/hptbul1/> `__
304
+ that we add a utility such as the one below to the standard library. We are
305
+ open to this idea, but do not see it as a core part of the proposal of this PEP
306
+ as it can be added as an enhancement later.
303
307
304
308
.. code-block :: python
305
309
@@ -329,19 +333,12 @@ justifies new language syntax.
329
333
References
330
334
==========
331
335
332
- .. [1 ] https://discuss.python.org/t/accepting-pep-654-exception-groups-and-except/10813/26
333
- .. [2 ] https://bugs.python.org/issue46431
334
- .. [3 ] this principle was established in the 2003 mail thread which led to :pep: `3134 `,
336
+ .. [1 ] this principle was established in the 2003 mail thread which led to :pep: `3134 `,
335
337
and included a proposal for a group-of-exceptions type!
336
338
https://mail.python.org/pipermail/python-dev/2003-January/032492.html
337
- .. [4 ] https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers
338
- .. [5 ] https://github.com/python/cpython/pull/30441
339
- .. [6 ] https://github.com/python/cpython/pull/29880
340
- .. [7 ] https://discuss.python.org/t/accepting-pep-654-exception-groups-and-except/10813/9
341
- .. [8 ] https://github.com/python/cpython/pull/28569#discussion_r721768348
342
- .. [9 ] https://bugs.python.org/issue45607
343
- .. [10 ] https://github.com/python/cpython/blob/69ef1b59983065ddb0b712dac3b04107c5059735/Lib/http/client.py#L596-L597
344
- .. [11 ] https://www.reddit.com/r/Python/comments/rmrvxv/pep_678_enriching_exceptions_with_notes/hptbul1/
339
+ .. [2 ] particularly those at https://bugs.python.org/issue45607,
340
+ https://discuss.python.org/t/accepting-pep-654-exception-groups-and-except/10813/9,
341
+ https://github.com/python/cpython/pull/28569#discussion_r721768348, and
345
342
346
343
347
344
0 commit comments