We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
_rate_limit_exceeded_handler
Describe the bug
Type annotation of Slowapi's _rate_limit_exceeded_handler is not matched with latest starlette annotations due to lack of consideration of Awaitable.
Awaitable
# _rate_limit_exceeded_handler Callable[[Request, RateLimitExceeded], Response] # Argument 2 to "add_exception_handler" of "Starlette" Callable[[Request, Exception], Response | Awaitable[Response]] | Callable[[WebSocket, Exception], Awaitable[None]]
After updating starlette to the latest it raises error.
https://results.pre-commit.ci/run/github/689781832/1707152173.Vq3hZuM6QlSEMvoYNuM7NQ
locloc/main.py:31: error: Argument 2 to "add_exception_handler" of "Starlette" has incompatible type "Callable[[Request, RateLimitExceeded], Response]"; expected "Union[Callable[[Request, Exception], Union[Response, Awaitable[Response]]], Callable[[WebSocket, Exception], Awaitable[None]]]" [arg-type] app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_hand...
To Reproduce
In 6547679:
from fastapi import FastAPI from slowapi import _rate_limit_exceeded_handler from slowapi.errors import RateLimitExceeded app = FastAPI() app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
docker run --rm -it python:3.12 bash pip install fastapi==0.109.2 mypy pip install git+https://github.com/laurentS/slowapi.git@6547679 cat <<'A'>app.py from fastapi import FastAPI from slowapi import _rate_limit_exceeded_handler from slowapi.errors import RateLimitExceeded app = FastAPI() app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) A mypy --strict app.py
root@bf2b20276907:/# mypy --strict app.py app.py:6: error: Argument 2 to "add_exception_handler" of "Starlette" has incompatible type "Callable[[Request, RateLimitExceeded], Response]"; expected "Callable[[Request, Exception], Response | Awaitable[Response]] | Callable[[WebSocket, Exception], Awaitable[None]]" [arg-type]
Expected behavior Mypy says Success: no issues found in 1 source file under strict mode.
Success: no issues found in 1 source file
Screenshots
Your app (please complete the following information):
fastapi or starlette?
fastapi
Version?
https://github.com/eggplants/locloc/tree/f737fae958571180e61e5e62f076b53b1c6ff585
slowapi version (have you tried with the latest version)?
6547679
Additional context
Starlette has started to check typing in mypy strict mode since v0.31.0. See encode/starlette#2180
The text was updated successfully, but these errors were encountered:
I'm running into this issue as well
Sorry, something went wrong.
"fix: issue laurentS#188"
0a2359b
No branches or pull requests
Describe the bug
Type annotation of Slowapi's
_rate_limit_exceeded_handler
is not matched with latest starlette annotations due to lack of consideration ofAwaitable
.After updating starlette to the latest it raises error.
https://results.pre-commit.ci/run/github/689781832/1707152173.Vq3hZuM6QlSEMvoYNuM7NQ
To Reproduce
In 6547679:
Expected behavior
Mypy says
Success: no issues found in 1 source file
under strict mode.Screenshots
Your app (please complete the following information):
fastapi
https://github.com/eggplants/locloc/tree/f737fae958571180e61e5e62f076b53b1c6ff585
6547679
Additional context
Starlette has started to check typing in mypy strict mode since v0.31.0. See encode/starlette#2180
The text was updated successfully, but these errors were encountered: