[DB-SIG] PEP 249 in obsolete for Python 3000
M.-A. Lemburg
mal at egenix.com
Thu Jan 29 21:47:03 CET 2009
On 2009-01-29 20:15, Vernon Cole wrote:
> 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".
True, but that's render the whole PEP 249 obsolete ;-)
Mark's proposal is the correct approach for Python 3.x (and as
a matter of fact, the generally accepted way of porting apps
using StandardError to Python 3.x, AFAIK).
I'll add a note to the PEP.
> 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.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Jan 29 2009)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the DB-SIG
mailing list