Skip to content

Fix two dead-code paths (slowapi_startup, callable scope on shared_limit)#270

Open
khreechari wants to merge 2 commits into
laurentS:masterfrom
khreechari:fix/dead-code-cleanup
Open

Fix two dead-code paths (slowapi_startup, callable scope on shared_limit)#270
khreechari wants to merge 2 commits into
laurentS:masterfrom
khreechari:fix/dead-code-cleanup

Conversation

@khreechari
Copy link
Copy Markdown

Two functions are broken :

— `Limiter.slowapi_startup` (NameError on an undefined `app`, never called anywhere).
— `Limit.scope` when given a callable (NameError on an undefined `request`, even though `shared_limit` docs advertise callable scope). 

This PR deletes the first, fixes the second by passing the request through to the callable, and adds a regression test. 

Net: **+3 tests, 0 regressions**, `ruff F821` and `vulture` both clean on the affected lines.

This method referenced an undefined `app` variable (NameError on call)
and was masked from mypy with # type: ignore. It has no callers anywhere
in the codebase, docs, or tests — it never worked and never ran.

Flagged by ruff F821 (undefined name) and vulture (unused method).
The Limit.scope property referenced an undefined `request` variable
when the scope was callable (wrappers.py:62), so any shared_limit() with
a callable scope would NameError on first invocation. The feature was
documented but never worked, and no test covered it.

Replace the property with scope_for(request: Request) and pass the
request through to the callable — matching how key_func receives the
request. Update the one caller in extension.py.

Add a regression test exercising callable scope: two routes sharing
the limit, with the scope keyed off a request header, verifying
that different header values get independent buckets and that shared
values exhaust across both routes.

Flagged by ruff F821 (undefined name `request`).
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

Successfully merging this pull request may close these issues.

1 participant