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

request parameter unable to be renamed #192

Open
DanBoghean opened this issue Apr 10, 2024 · 1 comment
Open

request parameter unable to be renamed #192

DanBoghean opened this issue Apr 10, 2024 · 1 comment

Comments

@DanBoghean
Copy link

DanBoghean commented Apr 10, 2024

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):

  • fastapi: 0.110.0
  • slowapi: 0.1.9
@TimTam950
Copy link

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

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