[DB-SIG] PEP 249 in obsolete for Python 3000

Vernon Cole vernondcole at gmail.com
Thu Jan 29 20:15:23 CET 2009


I am busy hacking on code in an attempt to make adodbapi actually work in
three environments: CPython 2.3 to 2.6, CPython 3.0, and IronPython. One of
the first things that failed, when attempting to run on Python 3.0, was the
test for exception definitions.  I quote:

The module should make all error information available through
> these 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).
>
> Error
>
> Exception that is the base class of all other error
> 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).
>

This is impossible with Python 3.0, since there is neither an "exceptions"
module nor a "StandardError".

Mark Hammond provided the following workaround:

try:
>     from exceptions import StandardError as _BaseException
> except ImportError:
>     # py3k
>     _BaseException = Exception
>
> class Error(_BaseException):
>     pass
>
> class Warning(_BaseException):
>     pass
>

This makes the code work fine, except that, by strict definition, it
violates the api.

So it would seem that we need to also patch the PEP.

How is that done?
--
Vernon Cole
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/db-sig/attachments/20090129/4a568f0f/attachment.htm>


More information about the DB-SIG mailing list