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

FAST003 doesn't detect params used in injected dependencies #13657

Open
cbornet opened this issue Oct 7, 2024 · 1 comment · May be fixed by #15364
Open

FAST003 doesn't detect params used in injected dependencies #13657

cbornet opened this issue Oct 7, 2024 · 1 comment · May be fixed by #15364
Labels
bug Something isn't working help wanted Contributions especially welcome preview Related to preview mode features rule Implementing or modifying a lint rule

Comments

@cbornet
Copy link

cbornet commented Oct 7, 2024

It seems that it would be possible for FAST003 to detect params used in injected dependencies.

  • List of keywords you searched for before creating this issue: FAST003
  • A minimal code snippet that reproduces the bug.
from fastapi import FastAPI, Depends
from typing import Annotated

app = FastAPI()

def foo(thing_id: str):
    return thing_id

@app.get("/things/{thing_id}")
async def read_thing(other: Annotated[str, Depends(foo)]):
    return other
  • The command you invoked
ruff check --select "FAST" --preview bar.py --isolated
bar.py:9:19: FAST003 Parameter `thing_id` appears in route path, but not in `read_thing` signature
   |
 7 |     return thing_id
 8 |
 9 | @app.get("/things/{thing_id}")
   |                   ^^^^^^^^^^ FAST003
10 | async def read_thing(other: Annotated[str, Depends(foo)]):
11 |     return other
   |
   = help: Add `thing_id` to function signature
  • The current Ruff version (ruff --version)
ruff --version
ruff 0.6.9

I would expect FAST003 to not be triggered in the snippet since thing_id is used in injected foo callable.

@MichaReiser MichaReiser added bug Something isn't working rule Implementing or modifying a lint rule preview Related to preview mode features labels Oct 7, 2024
@MichaReiser
Copy link
Member

That makes sense, thanks. An easy fix could be to skip the rule when we see a Depends annotation. A somewhat more elaborated fix would be to resolve the Depends's target and try to see if it has any parameter with the given name.

@MichaReiser MichaReiser added the help wanted Contributions especially welcome label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contributions especially welcome preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants