Skip to content
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

Merged
merged 9 commits into from
Mar 27, 2018
Merged

Async iterators payload #2873

merged 9 commits into from
Mar 27, 2018

Conversation

asvetlov
Copy link
Member

Implementation of #2802

@asvetlov asvetlov changed the title Async iterators payload [WIP] Async iterators payload Mar 24, 2018
@asvetlov
Copy link
Member Author

Working on docs

@codecov-io
Copy link

codecov-io commented Mar 24, 2018

Codecov Report

Merging #2873 into 3.1 will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
aiohttp/payload.py 98.95% <100%> (+0.21%) ⬆️
aiohttp/multipart.py 95.47% <100%> (ø) ⬆️
aiohttp/payload_streamer.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77623f8...5caa91d. Read the comment docs.

@asvetlov asvetlov changed the base branch from master to 3.1 March 25, 2018 12:41
@asvetlov asvetlov changed the title [WIP] Async iterators payload Async iterators payload Mar 25, 2018
@asvetlov
Copy link
Member Author

Ready for review

class AsyncIterablePayload(Payload):

def __init__(self, value, *args, **kwargs):
assert isinstance(value, AsyncIterable), \
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

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):
Copy link
Member

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?


def get(self, data, *args, **kwargs):
def get(self, data, _CHAIN=chain, *args, **kwargs):
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

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):
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


async def write(self, writer):
try:
while True:
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

async def write(self, writer):
try:
while True:
chunck = await self._iter.__anext__()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/chunck/chunk/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@asvetlov
Copy link
Member Author

Fixed everything except assert statements.

Working on asserts.

Thanks for review

Copy link
Member

@kxepal kxepal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGFM

@asvetlov
Copy link
Member Author

I've reverted the change for:

Here needs a check that self._iter is not None for the case when the same instance of this class will be used twice.

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.
Failing fast is even better but I not sure if we really need to add extra checks. Anyway, passing the same generator instance twice into itertools API leads to unpredictable behavior too without any protection. Why should aiohttp be stricter?

@kxepal
Copy link
Member

kxepal commented Mar 26, 2018

@asvetlov
No, I didn't ask for support. I was about to throw RuntimeError or sort of explicitly about that case instead of having weird AttributeError: 'NoneType' object has no attribute '__anext__'.

@asvetlov
Copy link
Member Author

Done

@asvetlov
Copy link
Member Author

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).

@asvetlov asvetlov merged commit 9f2de0d into 3.1 Mar 27, 2018
@asvetlov asvetlov deleted the async-payload branch March 27, 2018 12:39
@lock
Copy link

lock bot commented Oct 28, 2019

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.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants