laurentS / slowapi

A rate limiter for Starlette and FastAPI
https://pypi.org/project/slowapi/
MIT License
1.17k stars 74 forks source link

`request` parameter unable to be renamed #192

Open DanBoghean opened 5 months ago

DanBoghean commented 5 months ago

Describe the bug Right now any rate limited endpoints need to be provided the request parameter to function properly per the docs. It's not currently possible to rename this parameter to anything other than request. If a type hint of Request is provided for the parameter, it should be be allowed to be named _ for example so that we can avoid linter errors saying Parameter 'request' is not used

To Reproduce

@app.post('/v0/login')
@limiter.limit('5/hour')
def _serve_login_endpoint(
        request: Request, # This throws a linter error with ruff `Parameter 'request' value is not used`
        ...):
    ...

Renaming the request parameter to _ raises on exception Exception: No "request" or "websocket" argument on function "<function _serve_login_endpoint at 0x76e2501042c0>"

Expected behavior

@app.post('/v0/login')
@limiter.limit('5/hour')
def _serve_login_endpoint(
        _: Request, 
        ...):
    ...

Renaming the request parameter to _ and providing a type hint of Request should not throw the above exception.

Your app (please complete the following information):

TimTam950 commented 5 months ago

I have not actively contributed to this repo before, but was perusing it and will take a stab