slowapi icon indicating copy to clipboard operation
slowapi copied to clipboard

being able to ignore request parameter

Open aschenkuttel opened this issue 2 years ago • 5 comments

this allows users to use _ instead of request aswell which solves linter errors due the unused parameter I'm aware that this strays a bit away from the same convention as starlette but looks to me a bit more pythonic

aschenkuttel avatar Apr 12 '22 14:04 aschenkuttel

Hi @aschenkuttel thanks for raising this PR! In principle, I think it makes sense to try and resolve linter errors. I'm just wondering if there's a risk that some users might be using the _ argument for other purposes, which could collide with your usage of it. Granted, they would need to use the correct type annotation as well, which seems unlikely.

laurentS avatar Apr 26 '22 09:04 laurentS

I see what you mean but that should be already handled no? Since we still first check of the argument named request and only fallback onto the underscore if there's none?

So people are still able to use the request argument and ignore another one.

aschenkuttel avatar Apr 27 '22 06:04 aschenkuttel

I'm uncertain about whether using _ as a parameter is a positive change. To resolve linter errors, I'd instead encourage the annotation # noqa. From the library perspective, I'd rather default to the side of clarity.

twcurrie avatar Jun 17 '22 13:06 twcurrie

I still think the underscore would be a positive change since we're using it as intended:

The request parameter is not used (by the user) hence the usage of the underscore instead.

Forcing the user to have this parameter with even a specific naming is just a weird concept in my eyes.

aschenkuttel avatar Jul 04 '22 01:07 aschenkuttel

I agree, I think it's a bit clunky of a user experience. I think the proposal to shift this into an ASGI middleware implementation would remove the need to declare the request object as a variable to every endpoint function.

twcurrie avatar Jul 05 '22 12:07 twcurrie

Hi ! coming back to this PR that seems a bit forgotten:

  • I agree with @twcurrie and @laurentS here

From the library perspective, I'd rather default to the side of clarity. (twcurrie)

I'm just wondering if there's a risk that some users might be using the _ argument for other purposes (laurentS)

I would say there is one, but as you said it would need to have the request annotation as well. Maybe we could add a specific exception for the case where request is not defined, and _ is used for another purpose so that it is easier to debug.

Anyway, the #113 PR got merged, and Request doesn't have to be explicitely added, since it is created from the scope in the middleware: request = Request(scope, receive=receive, send=self.send), so we might close this PR

thentgesMindee avatar Nov 24 '22 09:11 thentgesMindee