Vizonex / Winloop

An Alternative library for uvloop compatability with windows
https://pypi.org/project/winloop
Apache License 2.0
89 stars 8 forks source link

Use UV_E* constants, OSError built-in translation. #15

Closed lschoe closed 8 months ago

lschoe commented 8 months ago

This PR avoids the hard-coded error numbers from the PR #14. Instead the available error numbers of the form UV_E* (hence with a single underscore _) are used in modules like stream.pyx and udp.pyx in winloop/handles/. The files uv.pxd and errors.pyx are modified accordingly, also taking advantage of the translation in Python's OSError(), which given an error number and error message automatically returns an instance from a subclass of OSError, like this:

>>> import errno
>>> OSError(errno.EAGAIN, '')
BlockingIOError(11, '')
>>> OSError(11, '')
BlockingIOError(11, '')
>>> OSError(errno.EAGAIN)  # conversion is not done if error message is left out
OSError(11)

Maybe the same approach also works for all other errors (incl. the socket errors). I don't really see why not? This also helps to keep the source code for Winloop as close as possible to the uvloop source code.

Vizonex commented 8 months ago

Looks good I have no complaints

Vizonex commented 8 months ago

@lschoe You could also do the same with socket errors since it doesn't kill any time and makes the code smaller.