bpo-42413: Replace concurrent.futures.TimeoutError and asyncio.TimeoutError with builtin TimeoutError#23520
bpo-42413: Replace concurrent.futures.TimeoutError and asyncio.TimeoutError with builtin TimeoutError#23520asvetlov wants to merge 5 commits intopython:mainfrom
Conversation
vstinner
left a comment
There was a problem hiding this comment.
I suggest to not deprecate the alias now.
| .. exception:: TimeoutError | ||
|
|
||
| The operation has exceeded the given deadline. | ||
| A deprecated alias of :exc:`TimeoutError`, |
There was a problem hiding this comment.
If you can to deprecated it, you need to add the ".. deprecated::" markup. For now, I suggest to keep it. There is no need to remove the alias.
In Python 3.10, we kept the IOError alias, even if it's no longer used.
There was a problem hiding this comment.
The text was copyed from @tiran PR about replacing a custom socket.timeout exception with an alias to TimeoutError: https://github.com/python/cpython/pull/23413/files#diff-e9e93d6b76a8a1cf0825d557b12e7ce3e67081cad650063eee520b81fd651943R286
I can change it to something else if you insist.
|
|
||
| class TimeoutError(Exception): | ||
| """The operation exceeded the given deadline.""" | ||
| TimeoutError = TimeoutError # make local alias for the standard exception |
There was a problem hiding this comment.
Would it be possible to move this one to asyncio/__init__.py?
Please mention "bpo-42413:" in the comment. Like:
# bpo-42413: asyncio.TimeoutError is now an alias to the builtin TimeoutError exception.
TimeoutError = TimeoutError
There was a problem hiding this comment.
We can but it increases a chance of backward incompatibility.
People still can use from asyncio.exceptions import TimeoutError.
I dislike this style and strive to avoid it personally, but I recall a lot of third-party code that uses such imports.
The main reason is that IDE or another tool can insert obj.__class__.__module__ when applies 'autoimport' to the edited python file.
PyCharm, for example, changed this behavior to substitute the top-most name (perform a lookup in __init__.py for the package) about a year ago after I discussed the feature with PyCharm devs at US PyCon 2019.
I'm not sure what other tools do.
Ideally, we can add some trick with module-level __getattr__ to raise a warning about bad usage but I'm really not sure if we should do it this PR.
| """The operation exceeded the given deadline.""" | ||
| pass | ||
|
|
||
| TimeoutError = TimeoutError # make local alias for the standard exception |
There was a problem hiding this comment.
Same remark, can it be moved to __init__.py and mention the bpo in the comment?
|
@tiran: Would it be possible to "un-deprecate" socket.timeout alias? Or do you consider that it's good to announce that it's a "deprecated" alias? For me, "deprecated" means "it's going to disappear soon, be warned". |
|
This PR is stale because it has been open for 30 days with no activity. |
|
Fixed by #30197 |
https://bugs.python.org/issue42413