From 86fe587f02a2bd317c9c92b567649b192bca91b1 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 4 Nov 2020 18:45:36 -0800 Subject: [PATCH 1/4] Update errors.rst Clarify exception chaining behaviour and give a reference to the library documentation. --- Doc/tutorial/errors.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 0ce96466e8c286..d2d8e2527788e5 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -301,8 +301,13 @@ This can be useful when you are transforming exceptions. For example:: The expression following the :keyword:`from` must be either an exception or ``None``. Exception chaining happens automatically when an exception is raised -inside an exception handler or :keyword:`finally` section. Exception chaining -can be disabled by using ``from None`` idiom: +inside an exception handler or :keyword:`finally` section, however in this case +``__context__`` attribute of the exception is used. Chaining with +``__context__`` works similarly, but when formatting exception traceback +``__cause__`` takes priority. For more information about chaining mechanics +see :ref:`bltin-exceptions`. + +Exception chaining can be disabled by using ``from None`` idiom: >>> try: ... open('database.sqlite') From c29f3a239ded54e3c3f4c682be78003fd0acd8ea Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 4 Nov 2020 18:52:38 -0800 Subject: [PATCH 2/4] Update errors.rst Wording --- Doc/tutorial/errors.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index d2d8e2527788e5..f8fc5814fe1a42 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -303,9 +303,9 @@ The expression following the :keyword:`from` must be either an exception or ``None``. Exception chaining happens automatically when an exception is raised inside an exception handler or :keyword:`finally` section, however in this case ``__context__`` attribute of the exception is used. Chaining with -``__context__`` works similarly, but when formatting exception traceback -``__cause__`` takes priority. For more information about chaining mechanics -see :ref:`bltin-exceptions`. +``__context__`` works similarly to chaining wit ``__cause__``, +but when formatting exception traceback ``__cause__`` takes priority. +For more information about chaining mechanics see :ref:`bltin-exceptions`. Exception chaining can be disabled by using ``from None`` idiom: From 35d34c39da262bd2362fefb96152cbbdddd649de Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 4 Nov 2020 18:55:29 -0800 Subject: [PATCH 3/4] Update errors.rst Spelling --- Doc/tutorial/errors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index f8fc5814fe1a42..2b4f2f53c08d0e 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -303,7 +303,7 @@ The expression following the :keyword:`from` must be either an exception or ``None``. Exception chaining happens automatically when an exception is raised inside an exception handler or :keyword:`finally` section, however in this case ``__context__`` attribute of the exception is used. Chaining with -``__context__`` works similarly to chaining wit ``__cause__``, +``__context__`` works similarly to chaining with ``__cause__``, but when formatting exception traceback ``__cause__`` takes priority. For more information about chaining mechanics see :ref:`bltin-exceptions`. From 2831bc0c019daa2e3281fadbc9c56db92225024b Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 9 Nov 2020 10:45:48 -0800 Subject: [PATCH 4/4] Update errors.rst Remove mentioning of special attributes as folks think it's too much for beginners. --- Doc/tutorial/errors.rst | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index c886c3a6b4dd6e..4a25861a050e61 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -312,13 +312,6 @@ disabled by using ``from None`` idiom: File "", line 4, in RuntimeError -There are two special attributes that enable chaining mechanics in -exceptions: ``__context__`` and ``__cause__``. When you raise an exception -inside :keyword:`except` or :keyword:`finally`, Pyhton automatically fills -``__context__`` attribute of the new exception with the caught one. When you -use ``from exc`` syntax, Pyhon fills ``__cause__`` attribute with -the ``exc``. You can use both attributes for introspection purposes, however -when formatting exception traceback message, ``__cause__`` takes priority. For more information about chaining mechanics, see :ref:`bltin-exceptions`.