10000 bpo-12029: [doc] clarify that except does not match virtual subclasses of the specified exception type by iritkatriel · Pull Request #32027 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-12029: [doc] clarify that except does not match virtual subclasses of the specified exception type #32027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 21, 2022
Prev Previous commit
Next Next commit
apply review comments
  • Loading branch information
iritkatriel committed Mar 21, 2022
commit e714ebf243fb305ccfcbfac0dc90a590afabb425
2 changes: 1 addition & 1 deletion Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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. [#]_
Expand Down
5 changes: 2 additions & 3 deletions Doc/reference/executionmodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down
6 changes: 3 additions & 3 deletions Doc/tutorial/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
0