From 39af31b2d7576793e42616c0eee2ca4fb74d47f6 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 21 Mar 2022 11:55:03 +0000 Subject: [PATCH 1/9] bpo-12029: [doc] clarify that except does not match virtual subclasses of the specified exception type --- 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 888740cdd0f196..022715c06693bb 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -121,9 +121,9 @@ may name multiple exceptions as a parenthesized tuple, for example:: ... pass A class in an :keyword:`except` clause is compatible with an exception if it is -the same class or a base class thereof (but not the other way around --- an -*except clause* listing a derived class is not compatible with a base class). -For example, the following code will print B, C, D in that order:: +the same class or a non-virtual base class thereof (but not the other way around +--- an *except clause* listing a derived class is not compatible with a base +class). For example, the following code will print B, C, D in that order:: class B(Exception): pass From e9fd87ede5fec0228fdc91ab93f6501f0432d7ab Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 21 Mar 2022 11:59:21 +0000 Subject: [PATCH 2/9] update reference as well --- Doc/reference/executionmodel.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/reference/executionmodel.rst b/Doc/reference/executionmodel.rst index e652915bd271c3..11eff0b4528c61 100644 --- a/Doc/reference/executionmodel.rst +++ b/Doc/reference/executionmodel.rst @@ -259,8 +259,9 @@ a stack traceback, except when the exception is :exc:`SystemExit`. Exceptions are identified by class instances. The :keyword:`except` clause is selected depending on the class of the instance: it must reference the class of -the instance or a base class thereof. The instance can be received by the -handler and can carry additional information about the exceptional condition. +the instance or a non-virtual base class thereof. The instance can be received +by the handler and can carry additional information about the exceptional +condition. .. note:: From 588bf278047b17848fa067d74ffcd050c38b5e89 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 21 Mar 2022 13:00:47 +0000 Subject: [PATCH 3/9] update the compound-statements reference as well --- Doc/reference/compound_stmts.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 15a51e7fc7bead..b507597c7ec47d 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -243,9 +243,8 @@ is found that matches the exception. An expression-less except clause, if present, must be last; it matches any exception. For an except clause with an expression, that expression is evaluated, and the clause matches the exception if the resulting object is "compatible" with the exception. An object is -compatible with an exception if the object is the class or a base class of the exception -object, or a tuple containing an item that is the class or a base class of -the exception object. +compatible with an exception if the object is the class or a non-virtual base +class of the exception object, or a tuple containing such an item. If no except clause matches the exception, the search for an exception handler continues in the surrounding code and on the invocation stack. [#]_ From e714ebf243fb305ccfcbfac0dc90a590afabb425 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 21 Mar 2022 14:35:30 +0000 Subject: [PATCH 4/9] apply review comments --- Doc/reference/compound_stmts.rst | 2 +- Doc/reference/executionmodel.rst | 5 ++--- Doc/tutorial/errors.rst | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index b507597c7ec47d..647b15efc7a1a9 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -244,7 +244,7 @@ present, must be last; it matches any exception. For an except clause with an expression, that expression is evaluated, and the clause matches the exception if the resulting object is "compatible" with the exception. An object is compatible with an exception if the object is the class or a non-virtual base -class of the exception object, or a tuple containing such an item. +class of the exception object, or a tuple containing one or more such items. If no except clause matches the exception, the search for an exception handler continues in the surrounding code and on the invocation stack. [#]_ diff --git a/Doc/reference/executionmodel.rst b/Doc/reference/executionmodel.rst index 11eff0b4528c61..1d66e093f49e19 100644 --- a/Doc/reference/executionmodel.rst +++ b/Doc/reference/executionmodel.rst @@ -259,9 +259,8 @@ a stack traceback, except when the exception is :exc:`SystemExit`. Exceptions are identified by class instances. The :keyword:`except` clause is selected depending on the class of the instance: it must reference the class of -the instance or a non-virtual base class thereof. The instance can be received -by the handler and can carry additional information about the exceptional -condition. +the instance or a non-virtual base class thereof. The instance can be received by the +handler and can carry additional information about the exceptional condition. .. note:: diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 022715c06693bb..f92b0de44c6b09 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -121,9 +121,9 @@ may name multiple exceptions as a parenthesized tuple, for example:: ... pass A class in an :keyword:`except` clause is compatible with an exception if it is -the same class or a non-virtual base class thereof (but not the other way around ---- an *except clause* listing a derived class is not compatible with a base -class). For example, the following code will print B, C, D in that order:: +the same class or a non-virtual base class thereof (but not the other way around --- an +*except clause* listing a derived class is not compatible with a base class). +For example, the following code will print B, C, D in that order:: class B(Exception): pass From 020ef95bbd9ac784f176c48d57c36e8b14d50ca0 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 21 Mar 2022 15:01:11 +0000 Subject: [PATCH 5/9] tweak wording --- Doc/reference/compound_stmts.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 647b15efc7a1a9..b507597c7ec47d 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -244,7 +244,7 @@ present, must be last; it matches any exception. For an except clause with an expression, that expression is evaluated, and the clause matches the exception if the resulting object is "compatible" with the exception. An object is compatible with an exception if the object is the class or a non-virtual base -class of the exception object, or a tuple containing one or more such items. +class of the exception object, or a tuple containing such an item. If no except clause matches the exception, the search for an exception handler continues in the surrounding code and on the invocation stack. [#]_ From faa806334d1c21cd7f651f30f8b1271ff8d39524 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 21 Mar 2022 15:18:49 +0000 Subject: [PATCH 6/9] revert shortcut in reference --- Doc/reference/compound_stmts.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index b507597c7ec47d..441b52bf4e4efc 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -244,7 +244,8 @@ present, must be last; it matches any exception. For an except clause with an expression, that expression is evaluated, and the clause matches the exception if the resulting object is "compatible" with the exception. An object is compatible with an exception if the object is the class or a non-virtual base -class of the exception object, or a tuple containing such an item. +class of the exception object, or a tuple containing the class or a non-virtual +base class of the exception object. If no except clause matches the exception, the search for an exception handler continues in the surrounding code and on the invocation stack. [#]_ From 195327b53107b166ae4bfd61db5365111de7f17d Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Mon, 21 Mar 2022 16:04:44 +0000 Subject: [PATCH 7/9] Update Doc/reference/compound_stmts.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Éric --- Doc/reference/compound_stmts.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 441b52bf4e4efc..a92db2c4d2a721 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -244,8 +244,8 @@ present, must be last; it matches any exception. For an except clause with an expression, that expression is evaluated, and the clause matches the exception if the resulting object is "compatible" with the exception. An object is compatible with an exception if the object is the class or a non-virtual base -class of the exception object, or a tuple containing the class or a non-virtual -base class of the exception object. +class of the exception object, or a tuple containing an item that is the class +or a non-virtual base class of the exception object. If no except clause matches the exception, the search for an exception handler continues in the surrounding code and on the invocation stack. [#]_ From 44d9ba0157f962517f052472ccb74b180bdaa1fa Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 21 Mar 2022 18:00:14 +0000 Subject: [PATCH 8/9] revert change to tutorial - this is too advanced to be mentioned there --- 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 f92b0de44c6b09..888740cdd0f196 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -121,7 +121,7 @@ may name multiple exceptions as a parenthesized tuple, for example:: ... pass A class in an :keyword:`except` clause is compatible with an exception if it is -the same class or a non-virtual base class thereof (but not the other way around --- an +the same class or a base class thereof (but not the other way around --- an *except clause* listing a derived class is not compatible with a base class). For example, the following code will print B, C, D in that order:: From a4ae779388292864531231f891c515099228e87e Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 21 Mar 2022 18:18:53 +0000 Subject: [PATCH 9/9] add reference to 'abrstract base class' --- Doc/reference/compound_stmts.rst | 7 ++++--- Doc/reference/executionmodel.rst | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index a92db2c4d2a721..92024e51ef4fc7 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -243,9 +243,10 @@ is found that matches the exception. An expression-less except clause, if present, must be last; it matches any exception. For an except clause with an expression, that expression is evaluated, and the clause matches the exception if the resulting object is "compatible" with the exception. An object is -compatible with an exception if the object is the class or a non-virtual base -class of the exception object, or a tuple containing an item that is the class -or a non-virtual base class of the exception object. +compatible with an exception if the object is the class or a +:term:`non-virtual base class ` of the exception object, +or a tuple containing an item that is the class or a non-virtual base class +of the exception object. If no except clause matches the exception, the search for an exception handler continues in the surrounding code and on the invocation stack. [#]_ diff --git a/Doc/reference/executionmodel.rst b/Doc/reference/executionmodel.rst index 1d66e093f49e19..d9183561820b2b 100644 --- a/Doc/reference/executionmodel.rst +++ b/Doc/reference/executionmodel.rst @@ -259,8 +259,9 @@ a stack traceback, except when the exception is :exc:`SystemExit`. Exceptions are identified by class instances. The :keyword:`except` clause is selected depending on the class of the instance: it must reference the class of -the instance or a non-virtual base class thereof. The instance can be received by the -handler and can carry additional information about the exceptional condition. +the instance or a :term:`non-virtual base class ` thereof. +The instance can be received by the handler and can carry additional information +about the exceptional condition. .. note::