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

incompatible type and expected "type[_MiddlewareClass[[]]]" [arg-type] #2912

Open
RaviMintel07 opened this issue Mar 20, 2025 · 3 comments
Open

Comments

@RaviMintel07
Copy link

Hi ,

am using asgi-logger and extended AccessLoggerMiddleware to customise the logging in the application and when I upgrade fastapi to 0.109.x version getting issue on mypy, any suggestions ?

error: Argument 1 to "Middleware" has incompatible type "type[AccessLoggerMiddleware]"; expected "type[_MiddlewareClass[[]]]" [arg-type]

middleware = [
    Middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_methods=["PUT", "GET", "DELETE"],
        allow_headers=["Authorization"],
    ),
    Middleware(access_logger.AccessLoggerMiddleware),
]

and this is my customise version of logging.

import structlog
from asgi_logger import middleware as asl
from asgiref.typing import ASGI3Application, HTTPScope


class AccessLoggerMiddleware(asl.AccessLoggerMiddleware):
   //code

@adriangb
Copy link
Member

what version of mypy are you using? have you tried updating to the latest version, or using pyright which generally in my experience is more reliable?

@RaviMintel07
Copy link
Author

I tried with mypy 1.15.0 as well but still same issue.

@adriangb
Copy link
Member

Can you offer a self-contained MRE?

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

No branches or pull requests

2 participants