8000 bpo-17188: DOC: Document 'from None' in raise statement (#1671) · stackless-dev/stackless@763557e · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 763557e

Browse files
csabellaterryjreedy
authored andcommitted
bpo-17188: DOC: Document 'from None' in raise statement (python#1671)
Original patch by Dennis Mårtensson.
1 parent d896985 commit 763557e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Doc/reference/simple_stmts.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ printed::
587587
...
588588
Traceback (most recent call last):
589589
File "<stdin>", line 2, in <module>
590-
ZeroDivisionError: int division or modulo by zero
590+
ZeroDivisionError: division by zero
591591

592592
The above exception was the direct cause of the following exception:
593593

@@ -606,17 +606,35 @@ attached as the new exception's :attr:`__context__` attribute::
606606
...
607607
Traceback (most recent call last):
608608
File "<stdin>", line 2, in <module>
609-
ZeroDivisionError: int division or modulo by zero
609+
ZeroDivisionError: division by zero
610610

611611
During handling of the above exception, another exception occurred:
612612

613613
Traceback (most recent call last):
614614
File "<stdin>", line 4, in <module>
615615
RuntimeError: Something bad happened
616616

617+
Exception chaining can be explicitly suppressed by specifying :const:`None` in
618+
the ``from`` clause::
619+
620+
>>> try:
621+
... print(1 / 0)
622+
... except:
623+
... raise RuntimeError("Something bad happened") from None
624+
...
625+
Traceback (most recent call last):
626+
File "<stdin>", line 4, in <module>
627+
RuntimeError: Something bad happened
628+
617629
Additional information on exceptions can be found in section :ref:`exceptions`,
618630
and information about handling exceptions is in section :ref:`try`.
619631

632+
.. versionchanged:: 3.3
633+
:const:`None` is now permitted as ``Y`` in ``raise X from Y``
634+
635+
.. versionadded:: 3.3
636+
The ``__suppress_context__`` attribute to suppress automatic display of the
637+
exception context
620638

621639
.. _break:
622640

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ David Marek
965965
Doug Marien
966966
Sven Marnach
967967
Alex Martelli
968+
Dennis Mårtensson
968969
Anthony Martin
969970
Owen Martin
970971
Sidney San Martín

0 commit comments

Comments
 (0)
0