Skip to content
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

PEP 249: Replace StandardError with Exception #2781

Merged
merged 6 commits into from
Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions pep-0249.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ exceptions or subclasses thereof:
`Warning`_
Exception raised for important warnings like data truncations
while inserting, etc. It must be a subclass of the Python
``StandardError`` (defined in the module exceptions).
``Exception`` class [10]_ [11]_.


.. _Error:
Expand All @@ -128,7 +128,7 @@ exceptions or subclasses thereof:
exceptions. You can use this to catch all errors with one single
``except`` statement. Warnings are not considered errors and thus
should not use this class as base. It must be a subclass of the
Python ``StandardError`` (defined in the module exceptions).
Python ``Exception`` class [10]_.


.. _InterfaceError:
Expand Down Expand Up @@ -199,9 +199,11 @@ exceptions or subclasses thereof:
or has transactions turned off. It must be a subclass of
DatabaseError_.

This is the exception inheritance layout::
This is the exception inheritance layout [10]_ [11]_:

StandardError
.. code-block:: text

Exception
|__Warning
|__Error
|__InterfaceError
Expand Down Expand Up @@ -731,14 +733,12 @@ Implementation Hints for Module Authors
constructor.

* Here is a snippet of Python code that implements the exception
hierarchy defined above::

import exceptions
hierarchy defined above [10]_::

class Error(exceptions.StandardError):
class Error(Exception):
pass

class Warning(exceptions.StandardError):
class Warning(Exception):
pass

class InterfaceError(Error):
Expand Down Expand Up @@ -1297,6 +1297,20 @@ Footnotes
``WHERE`` clause, or clearly document a different interpretation
of the ``.rowcount`` attribute.

.. [10] In Python 2 and earlier versions of this PEP, ``StandardError``
was used as the base class for all DB-API exceptions. Since
``StandardError`` was removed in Python 3, database modules
targeting Python 3 should use ``Exception`` as base class instead.
The PEP was updated to use ``Exception`` throughout the text, to
avoid confusion. The change should not affect existing modules or
uses of those modules, since all DB-API error exception classes are
still rooted at the ``Error`` or ``Warning`` classes.

.. [11] In a future revision of the DB-API, the base class for
``Warning`` will likely change to the builtin ``Warning`` class. At
the time of writing of the DB-API 2.0 in 1999, the warning framework
in Python did not yet exist.


Acknowledgements
================
Expand Down