-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Async iterators payload #2873
Async iterators payload #2873
Conversation
Working on docs |
Codecov Report
@@ Coverage Diff @@
## 3.1 #2873 +/- ##
==========================================
+ Coverage 97.97% 97.98% +<.01%
==========================================
Files 39 39
Lines 7464 7499 +35
Branches 1310 1316 +6
==========================================
+ Hits 7313 7348 +35
Misses 48 48
Partials 103 103
Continue to review full report at Codecov.
|
Ready for review |
aiohttp/payload.py
Outdated
class AsyncIterablePayload(Payload): | ||
|
||
def __init__(self, value, *args, **kwargs): | ||
assert isinstance(value, AsyncIterable), \ |
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.
Shouldn't here be a regular if not isinstace: raise TypeError
check?
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.
It should probably but other classes in the module use assert
statements.
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.
Ok.
aiohttp/payload.py
Outdated
def get_payload(data, *args, **kwargs): | ||
return PAYLOAD_REGISTRY.get(data, *args, **kwargs) | ||
|
||
|
||
def register_payload(factory, type): | ||
def register_payload(factory, type, *, order=Order.normal): |
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.
order
is unused here. Any reasons to pass it there?
aiohttp/payload.py
Outdated
|
||
def get(self, data, *args, **kwargs): | ||
def get(self, data, _CHAIN=chain, *args, **kwargs): |
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.
Shouln't _CHAIN
be keyword-only argument? Otherwise it will be overrided by a second argument which should get into args
.
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.
good catch
aiohttp/payload.py
Outdated
if isinstance(data, type): | ||
return factory(data, *args, **kwargs) | ||
|
||
raise LookupError() | ||
|
||
def register(self, factory, type): | ||
self._registry.append((factory, type)) | ||
def register(self, factory, type, order=Order.normal): |
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.
Everywhere else order
is keyword-only argument. Shouldn't it be there the same for consistency?
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.
fixed
aiohttp/payload.py
Outdated
|
||
async def write(self, writer): | ||
try: | ||
while True: |
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.
Here need a check that self._iter
is not None for the case when the same instance of this class will be used twice.
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.
Done
aiohttp/payload.py
Outdated
async def write(self, writer): | ||
try: | ||
while True: | ||
chunck = await self._iter.__anext__() |
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.
s/chunck/chunk/
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.
fixed
Fixed everything except assert statements. Working on asserts. Thanks for review |
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.
LGFM
I've reverted the change for:
Don't want to support such trick case. If an instance of the class will be used twice -- this is not intended behavior, better to fail in the case. |
@asvetlov |
Done |
async generators have an internal check for the case but I want to support any async iterable object (which could have no such strict checking). |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
Implementation of #2802