Skip to content

Commit 00b381b

Browse files
csabellaMariatta
authored andcommitted
bpo-17188: DOC: Document 'from None' in raise statement (GH-1671) (GH-1867)
Original patch by Dennis Mårtensson. (cherry picked from commit 763557e)
1 parent 03c7600 commit 00b381b

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
@@ -963,6 +963,7 @@ David Marek
963963
Doug Marien
964964
Sven Marnach
965965
Alex Martelli
966+
Dennis Mårtensson
966967
Anthony Martin
967968
Owen Martin
968969
Sidney San Martín

0 commit comments

Comments
 (0)