]> granicus.if.org Git - python/commitdiff
bpo-17188: DOC: Document 'from None' in raise statement (#1671)
authorcsabella <chekat2@gmail.com>
Sat, 20 May 2017 06:48:28 +0000 (02:48 -0400)
committerterryjreedy <tjreedy@udel.edu>
Sat, 20 May 2017 06:48:28 +0000 (02:48 -0400)
Original patch by Dennis Mårtensson.

Doc/reference/simple_stmts.rst
Misc/ACKS

index 63d0ea5e776a8e8eeae9fd1acde793459e7bce78..2429f11fd180a68e1e4f614e0aa03af1e1617564 100644 (file)
@@ -587,7 +587,7 @@ printed::
    ...
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
-   ZeroDivisionError: int division or modulo by zero
+   ZeroDivisionError: division by zero
 
    The above exception was the direct cause of the following exception:
 
@@ -606,7 +606,7 @@ attached as the new exception's :attr:`__context__` attribute::
    ...
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
-   ZeroDivisionError: int division or modulo by zero
+   ZeroDivisionError: division by zero
 
    During handling of the above exception, another exception occurred:
 
@@ -614,9 +614,27 @@ attached as the new exception's :attr:`__context__` attribute::
      File "<stdin>", line 4, in <module>
    RuntimeError: Something bad happened
 
+Exception chaining can be explicitly suppressed by specifying :const:`None` in
+the ``from`` clause::
+
+   >>> try:
+   ...     print(1 / 0)
+   ... except:
+   ...     raise RuntimeError("Something bad happened") from None
+   ...
+   Traceback (most recent call last):
+     File "<stdin>", line 4, in <module>
+   RuntimeError: Something bad happened
+
 Additional information on exceptions can be found in section :ref:`exceptions`,
 and information about handling exceptions is in section :ref:`try`.
 
+.. versionchanged:: 3.3
+    :const:`None` is now permitted as ``Y`` in ``raise X from Y``
+
+.. versionadded:: 3.3
+    The ``__suppress_context__`` attribute to suppress automatic display of the
+    exception context
 
 .. _break:
 
index 246a50be00763d1edbaf2ba11a68323c703e6829..d00fa79c6081a93d9b665c8975a2dd1b51d3b507 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -965,6 +965,7 @@ David Marek
 Doug Marien
 Sven Marnach
 Alex Martelli
+Dennis Mårtensson
 Anthony Martin
 Owen Martin
 Sidney San Martín