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 3 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`` [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`` [10]_.


.. _InterfaceError:
Expand Down Expand Up @@ -201,8 +201,8 @@ exceptions or subclasses thereof:

This is the exception inheritance layout::

malemburg marked this conversation as resolved.
Show resolved Hide resolved
StandardError
|__Warning
Exception [10]_
|__Warning [11]_
malemburg marked this conversation as resolved.
Show resolved Hide resolved
|__Error
|__InterfaceError
|__DatabaseError
Expand Down Expand Up @@ -731,14 +731,12 @@ Implementation Hints for Module Authors
constructor.

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

import exceptions

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 +1295,22 @@ 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.
Both ``StandardError`` and ``Exception`` are available as builtin
malemburg marked this conversation as resolved.
Show resolved Hide resolved
exception objects. 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 had not yet existed.
malemburg marked this conversation as resolved.
Show resolved Hide resolved


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