[Python-Dev] [Python-checkins] r45925 - in python/trunk: Lib/tempfile.py Lib/test/test_os.py Misc/NEWS Modules/posixmodule.c

M.-A. Lemburg mal at egenix.com
Wed May 10 21:51:24 CEST 2006

Martin v. Löwis wrote:
> I'm saying that changing WindowsError to include set errno
> to DOS error codes would *also* be an incompatible change.
>> Since code catching IOError will also see any WindowsError
>> exception, I'd opt for making .errno always return the
>> DOS/BSD error codes and have WindowsError grow an
>> additional .winerrno attribute which contains the
>> more fine-grained Win32 error code.
> Ok. I'll try to come up with a patch, but let me repeat
> this: even though this would nearly restore the behavior
> for the functions that I changed, it would *a different*
> incompatible change, since it would change the behavior
> of the places that *currently* (i.e. in 2.4)
> raise WindowsError.

Thanks !

I know that this will be a different incompatible change,
but only for the better, I think.

The only way around this breakage I see would be to introduce
the ErrorCode integer sub-class I posted on the checkins list
which then allows .errno to also compare equal to the .winerrno
values as well:

# Error code objects
class ErrorCode(int):
    values = ()
    def __new__(cls, basevalue, *aliasvalues):
        return int.__new__(cls, basevalue)
    def __init__(self, basevalue, *aliasvalues):
        self.values = (basevalue,) + aliasvalues
    def __cmp__(self, other):
        if other in self.values:
            return 0
        if other < self.values:
            return 1
            return -1

EEXISTS = ErrorCode(17, 183, 80)

I'm not sure whether it's worth the trouble.

BTW, and intended as offer for compromise, should we instead
add the Win32 codes to the errno module (or a new winerrno
module) ?! I can write a parser that takes winerror.h and
generates the module code.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, May 10 2006)
>>> 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 mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::

More information about the Python-Dev mailing list