Skip to content

Commit 7703958

Browse files
authored
PEP 249: Replace StandardError with Exception (#2781)
* Replace StandardError with Exception to avoid confusion when using the DB-API 2.0 in the context of Python 3. Add a note about a future upgrade to the Warning base class. Fixes #2776. * Fix typo and add year for more context. * Remove mention of the exceptions module This was removed in Python 3 as well. Python 2.7 doesn't need it either, since all standard exceptions are builtin objects. * Remove mention of exception objects being builtins. They were already for a very long time, so this is pointless. I only had this sentence to explain why I had removed the "import exceptions" line from the Python 2 days. * Grammar fix * Fix exception hierarchy formatting
1 parent e7446a1 commit 7703958

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

pep-0249.txt

+23-9
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ exceptions or subclasses thereof:
118118
`Warning`_
119119
Exception raised for important warnings like data truncations
120120
while inserting, etc. It must be a subclass of the Python
121-
``StandardError`` (defined in the module exceptions).
121+
``Exception`` class [10]_ [11]_.
122122

123123

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

133133

134134
.. _InterfaceError:
@@ -199,9 +199,11 @@ exceptions or subclasses thereof:
199199
or has transactions turned off. It must be a subclass of
200200
DatabaseError_.
201201

202-
This is the exception inheritance layout::
202+
This is the exception inheritance layout [10]_ [11]_:
203203

204-
StandardError
204+
.. code-block:: text
205+
206+
Exception
205207
|__Warning
206208
|__Error
207209
|__InterfaceError
@@ -731,14 +733,12 @@ Implementation Hints for Module Authors
731733
constructor.
732734

733735
* Here is a snippet of Python code that implements the exception
734-
hierarchy defined above::
735-
736-
import exceptions
736+
hierarchy defined above [10]_::
737737

738-
class Error(exceptions.StandardError):
738+
class Error(Exception):
739739
pass
740740

741-
class Warning(exceptions.StandardError):
741+
class Warning(Exception):
742742
pass
743743

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

1300+
.. [10] In Python 2 and earlier versions of this PEP, ``StandardError``
1301+
was used as the base class for all DB-API exceptions. Since
1302+
``StandardError`` was removed in Python 3, database modules
1303+
targeting Python 3 should use ``Exception`` as base class instead.
1304+
The PEP was updated to use ``Exception`` throughout the text, to
1305+
avoid confusion. The change should not affect existing modules or
1306+
uses of those modules, since all DB-API error exception classes are
1307+
still rooted at the ``Error`` or ``Warning`` classes.
1308+
1309+
.. [11] In a future revision of the DB-API, the base class for
1310+
``Warning`` will likely change to the builtin ``Warning`` class. At
1311+
the time of writing of the DB-API 2.0 in 1999, the warning framework
1312+
in Python did not yet exist.
1313+
13001314

13011315
Acknowledgements
13021316
================

0 commit comments

Comments
 (0)