-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-34622: Extract asyncio exceptions into a separate module #9141
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f4ef6ab
Extract asyncio exceptions into a separate module
asvetlov 623367e
Move SendfileNotAvailableError
asvetlov f70bb87
Add NEWS entry
asvetlov 9b139ca
Create own asyncio exception classes inherited from corresponing conc…
asvetlov f9a42fc
Cache exception type
asvetlov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""asyncio exceptions.""" | ||
|
||
|
||
__all__ = ('CancelledError', 'InvalidStateError', 'TimeoutError', | ||
'IncompleteReadError', 'LimitOverrunError', | ||
'SendfileNotAvailableError') | ||
|
||
import concurrent.futures | ||
from . import base_futures | ||
|
||
|
||
class CancelledError(concurrent.futures.CancelledError): | ||
"""The Future or Task was cancelled.""" | ||
|
||
|
||
class TimeoutError(concurrent.futures.TimeoutError): | ||
"""The operation exceeded the given deadline.""" | ||
|
||
|
||
class InvalidStateError(concurrent.futures.InvalidStateError): | ||
"""The operation is not allowed in this state.""" | ||
|
||
|
||
class SendfileNotAvailableError(RuntimeError): | ||
"""Sendfile syscall is not available. | ||
|
||
Raised if OS does not support sendfile syscall for given socket or | ||
file type. | ||
""" | ||
|
||
|
||
class IncompleteReadError(EOFError): | ||
""" | ||
Incomplete read error. Attributes: | ||
|
||
- partial: read bytes string before the end of stream was reached | ||
- expected: total number of expected bytes (or None if unknown) | ||
""" | ||
def __init__(self, partial, expected): | ||
super().__init__(f'{len(partial)} bytes read on a total of ' | ||
f'{expected!r} expected bytes') | ||
self.partial = partial | ||
self.expected = expected | ||
|
||
def __reduce__(self): | ||
return type(self), (self.partial, self.expected) | ||
|
||
|
||
class LimitOverrunError(Exception): | ||
"""Reached the buffer limit while looking for a separator. | ||
|
||
Attributes: | ||
- consumed: total number of to be consumed bytes. | ||
""" | ||
def __init__(self, message, consumed): | ||
super().__init__(message) | ||
self.consumed = consumed | ||
|
||
def __reduce__(self): | ||
return type(self), (self.args[0], self.consumed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why define subclasses instead of just making aliases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main motivation is to improve usability. There's no fundamental reason why these exceptions are derived from
concurrent.future
, it happened pretty much by accident. But the problem is that asyncio users seeconcurrent.future.TimeoutError
exceptions occurring in their programs and have no idea why it's notasyncio.TimeoutError
.Moreover, we have a plan to make
asyncio.CancelledError
aBaseException
in a follow up PR.