-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Feature or enhancement
Proposal:
Abstract
Sometimes there might be a case when a block inside async with asyncio.timeout(10)
can raise TimeoutError and there are no proper way to identify one TimeoutError from another.
async with asyncio.timeout(10):
if ...:
raise TimeoutError
then here engineers will not be able to identify from where TimeoutError was received
Simplest example
import asyncio
async def main():
try:
async with asyncio.timeout(1):
raise TimeoutError
except asyncio.TimeoutError: # will catch both, but should only exception from asyncio.timeout
print('catched asyncio.TimeoutError')
asyncio.run(main())
More complex example
try:
async with asyncio.timeout(10):
if ...:
raise TimeoutError
except TimeoutError: # will catch both
pass
except asyncio.TimeoutError: # will catch both, but should only exception from asyncio.timeout
pass
Proposal
asyncio should raise asyncio.TimeoutError from asyncio.exceptions and use some kind of inheritance, e.g.
class TimeoutError(builtins.TimeoutError):
pass
then engineers will be able to use native TimeoutError from builtins as well as asyncio.TimeoutError for their try/except or isinstance checks.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done