asgi-logger icon indicating copy to clipboard operation
asgi-logger copied to clipboard

mypy does not typecheck AccessLoggerMiddleware as starlette's Middleware class

Open just-maiyak opened this issue 7 months ago • 0 comments

I have the following minimal ASGI application :

import logging

from asgi_logger import AccessLoggerMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware


app = Starlette(
    middleware=[
        Middleware(
            AccessLoggerMiddleware,
            format="%(s)s",
            logger=logging.getLogger("testlogger"),
        )
    ]
)

Since starlette 0.35+, running mypy on it will produce the error :

main.py:11: error: Argument 1 to "Middleware" has incompatible type "type[AccessLoggerMiddleware]"; expected "type[_MiddlewareClass[[str, Logger]]]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

I feel like this is tied to this discussion over on starlette, but I cannot pinpoint the exact problem for now.

just-maiyak avatar Jul 09 '24 08:07 just-maiyak