diff --git a/fastapi/applications.py b/fastapi/applications.py index 9598dad5af..19a2014efa 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -1029,13 +1029,13 @@ class FastAPI(Starlette): exception_handlers[key] = value middleware = ( - [Middleware(ServerErrorMiddleware, handler=error_handler, debug=debug)] # type: ignore[invalid-argument-type] + [Middleware(ServerErrorMiddleware, handler=error_handler, debug=debug)] # ty: ignore[invalid-argument-type] + self.user_middleware + [ Middleware( - ExceptionMiddleware, + ExceptionMiddleware, # ty: ignore[invalid-argument-type] handlers=exception_handlers, - debug=debug, # type: ignore[invalid-argument-type] + debug=debug, ), # Add FastAPI-specific AsyncExitStackMiddleware for closing files. # Before this was also used for closing dependencies with yield but @@ -1056,7 +1056,7 @@ class FastAPI(Starlette): # user middlewares, the same context is used. # This is currently not needed, only for closing files, but used to be # important when dependencies with yield were closed here. - Middleware(AsyncExitStackMiddleware), # type: ignore[invalid-argument-type] + Middleware(AsyncExitStackMiddleware), # ty: ignore[invalid-argument-type] ] ) @@ -4638,7 +4638,7 @@ class FastAPI(Starlette): """ def decorator(func: DecoratedCallable) -> DecoratedCallable: - self.add_middleware(BaseHTTPMiddleware, dispatch=func) # type: ignore[arg-type] + self.add_middleware(BaseHTTPMiddleware, dispatch=func) # ty: ignore[invalid-argument-type] return func return decorator