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

Wrong type hint for tracing Signal sequence #3595

Closed
stj opened this issue Feb 6, 2019 · 4 comments
Closed

Wrong type hint for tracing Signal sequence #3595

stj opened this issue Feb 6, 2019 · 4 comments
Labels

Comments

@stj
Copy link
Contributor

stj commented Feb 6, 2019

Long story short

Type hints for tracing Signal contents look wrong.

Expected behaviour

mypy does not report an error when adding handlers to a signal object.

Actual behaviour

mypy reports an error of

error: List item 0 has incompatible type "Callable[[ClientSession, SimpleNamespace, TraceConnectionCreateEndParams], Coroutine[Any, Any, None]]"; expected "Callable[[TraceConfig], Awaitable[None]]"

Steps to reproduce

Run mypy over this snippet

import types

import aiohttp
import datadog

async def reuse_keepalive_connection(
    session: aiohttp.ClientSession,
    trace_config_ctx: types.SimpleNamespace,
    params: aiohttp.TraceConnectionReuseconnParams,
) -> None:
    """statsd counter; how often has a connection been reused"""
    datadog.statsd.increment("client.request.connection.reuse")

tracer = aiohttp.TraceConfig()
tracer.on_connection_reuseconn.extend([reuse_keepalive_connection])

Your environment

aiohttp 3.5.4
python 3.7.2
mypy 0.660

@aio-libs-bot
Copy link

GitMate.io thinks the contributor most likely able to help you is @asvetlov.

Possibly related issues are #401 (Signals), #1749 (Type hinting in code), #3230 (iter_chunks type annotation wrong), #3032 (Doc: signals), and #1309 (Client Tracing).

@asvetlov
Copy link
Member

asvetlov commented May 8, 2019

Fixed by #3596

@mvbrn
Copy link

mvbrn commented May 4, 2020

The similar issue still appears for me:

class RequestLogger:
    async def _on_request_start(
        self,
        session: aiohttp.ClientSession,
        context: SimpleNamespace,
        params: aiohttp.TraceRequestStartParams,
    ) -> None:
        ...

    def make_trace_config(self):
        tc = aiohttp.TraceConfig()
        tc.on_request_start.append(self._on_request_start)
        return tc

results with:

 error: Argument 1 to "append" of "MutableSequence" has incompatible type "Callable[[ClientSession, SimpleNamespace, TraceRequestStartParams], Coroutine[Any, Any, None]]"; expected "Callable[[ClientSession, SimpleNamespace, <union: 15 items>], Awaitable[None]]"

Python 3.7.7
mypy 0.770

@asvetlov
Copy link
Member

type annotation is reimplemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants