Skip to content

Middleware _MiddlewareClass mypy typing PR2381 #2581

Discussion options

You must be logged in to vote

You should be able to fix the issue by providing complete type annotations to your TraceTokenLoggerMiddleware:

from typing import Any

from starlette.middleware import Middleware
from starlette.types import ASGIApp, Receive, Scope, Send


IAsyncLogger = Any  # whatever the type is


class TraceTokenLoggerMiddleware:
    def __init__(self, app: ASGIApp, logger: IAsyncLogger) -> None:
        self._app = app
        self._async_logger = logger

    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
        # do something
        pass

async_logger: IAsyncLogger = NotImplemented

Middleware(TraceTokenLoggerMiddleware, logger=async_logger)  # no errors here

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@pawelrubin
Comment options

@adriangb
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ShedPlant
Comment options

Answer selected by ShedPlant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants