[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-23 Thread STINNER Victor
STINNER Victor added the comment: I see this issue as a follow-up of PEP 3151 which started to uniformize IOError, OSError and many variants that we had in Python 2. socket.timeout was introduced as a subclass of TimeoutError according to:

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-23 Thread STINNER Victor
STINNER Victor added the comment: IMHO it's ok that exc.errno is None. It doesn't prevent to write code like: except OSError as exc: if exc.errno == ...: ... else: ... In the early days (first 5 years? :-D) of the asyncio documentation, TimeoutError was documented

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This is a good idea. Writing IsADirectoryError(errno.EISDIR, os.strerror(errno.EISDIR), filename) is boring. -- ___ Python tracker ___

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Christian Heimes
Christian Heimes added the comment: There is another option: The subclasses of OSError could set a correct errno automatically. -- ___ Python tracker ___

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Andrew Svetlov
Andrew Svetlov added the comment: Thus using bare TimeoutError in asyncio is safe, isn't it? This is good news! -- ___ Python tracker ___

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I fixed many instantiations of OSError subclasses, but many are still left in Python code. -- ___ Python tracker ___

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Andrew Svetlov
Andrew Svetlov added the comment: I know that I just create OSError() with errno set to None. My question is: has the standard library such code examples already? In other words, how many third-party code will be broken by catching OSError with errno=None? --

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Christian Heimes
Christian Heimes added the comment: They have an errno attribute, it's just to None by default. You have to call OSError with multiple arguments to set errno to a non-None value. -- ___ Python tracker

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Yes, I think this is a problem. It is expected that an instance of OSError has valid errno. OSError is a merge of several old exception types, some of them did have errno, and others did not. Maybe add BaseTimeoutError and make TimeoutError a subclass of

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Andrew Svetlov
Andrew Svetlov added the comment: Perhaps it is a good compromise. OSError-derived class without errno looks getter to me that different incompatible TimeoutError classes. How many exceptions inherited from OSError have no errno set? Do we have a precedent in stdlib at all already?

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Christian Heimes
Christian Heimes added the comment: PyErr_SetString(PyErr_TimeoutError, "msg") and raise TimeoutError("msg") do not set any additional exception attributes. errno, strerror, filename, and filename2 are None: >>> try: ... raise TimeoutError("msg") ... except Exception as e: ... err =

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Andrew Svetlov
Andrew Svetlov added the comment: In futures and asyncio TimeoutError has no errno. I'm not sure should we care but I consider it as a show stopper. On another hand, two distinct timeout classes confuse people. I had many conversions about this during the aiohttp support. asyncio can raise

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Christian Heimes
Christian Heimes added the comment: Thanks Serhiy! Andrew, Antoine, Yury, do you want to replace the custom Timeout exceptions in asyncio, multiprocessing, and concurrent with global TimeoutError, too? -- nosy: +asvetlov, bquinlan, davin, pitrou, yselivanov resolution: fixed ->

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: There are also other distinct exceptions: multiprocessing.TimeoutError concurrent.futures.TimeoutError asyncio.TimeoutError -- nosy: +serhiy.storchaka ___ Python tracker

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-20 Thread Christian Heimes
Change by Christian Heimes : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-20 Thread miss-islington
miss-islington added the comment: New changeset 03c8ddd9e94c7bddf1f06cf785027b8d2bf00ff0 by Christian Heimes in branch 'master': bpo-42413: socket.timeout is now an alias of TimeoutError (GH-23413) https://github.com/python/cpython/commit/03c8ddd9e94c7bddf1f06cf785027b8d2bf00ff0 --

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-19 Thread Christian Heimes
Change by Christian Heimes : -- keywords: +patch pull_requests: +22306 stage: -> patch review pull_request: https://github.com/python/cpython/pull/23413 ___ Python tracker

[issue42413] Replace custom exception socket.timeout with TimeoutError

2020-11-19 Thread Christian Heimes
New submission from Christian Heimes : The socket module has a custom timeout exception "socket.timeout". The exception is documented https://docs.python.org/3/library/socket.html#socket.timeout as : > A subclass of OSError, this exception is raised when a timeout occurs on a > socket which