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

Specify type of stream_reader_factory #208

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aioresponses/compat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import asyncio # noqa: F401
import sys
from typing import Dict, Optional, Union # noqa
from typing import Dict, Optional, Union, Callable # noqa
from urllib.parse import parse_qsl, urlencode

from aiohttp import __version__ as aiohttp_version, StreamReader
Expand All @@ -16,6 +16,9 @@

AIOHTTP_VERSION = parse_version(aiohttp_version)

stream_reader_factory: Callable[
[Optional[asyncio.AbstractEventLoop]], StreamReader
]
if AIOHTTP_VERSION >= parse_version('3.0.0'):
Comment on lines 18 to 22
Copy link
Contributor

Choose a reason for hiding this comment

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

If mypy reports that error: All conditional function variants must have identical signatures [misc], wouldn't it be better to just add correct type annotations to both variants of stream_reader_factory?

if AIOHTTP_VERSION >= parse_version('3.0.0'):
    from aiohttp.client_proto import ResponseHandler

    def stream_reader_factory(
        loop: Optional[asyncio.AbstractEventLoop] = None
    ) -> StreamReader:
        protocol = ResponseHandler(loop=loop)
        return StreamReader(protocol, limit=2 ** 16, loop=loop)

else:

    def stream_reader_factory(
        loop: Optional[asyncio.AbstractEventLoop] = None
    ) -> StreamReader:
        return StreamReader()

from aiohttp.client_proto import ResponseHandler

Expand Down