-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[FAST002] FastAPI dependency without Annotated
unsafe fix error
#12982
Labels
bug
Something isn't working
fixes
Related to suggested fixes for violations
good first issue
Good for newcomers
preview
Related to preview mode features
Comments
mbrulatout
changed the title
[Fix error] FAST002 FastAPI dependency without
[FAST002] FastAPI dependency without Aug 19, 2024
Annotated
unsafe fixAnnotated
unsafe fix
mbrulatout
changed the title
[FAST002] FastAPI dependency without
[FAST002] FastAPI dependency without Aug 19, 2024
Annotated
unsafe fixAnnotated
unsafe fix error
For reproduction, it's important that the code has the relevant imports: from fastapi import Depends, FastAPI, APIRouter
datacenter_state_router = APIRouter()
@datacenter_state_router.patch(
"/{name}",
)
async def datacenter_state_patch(
current_state: DatacenterState = PermissionDepends(
Permission.WRITE, get_datacenter_state
),
session: Session = Depends(database_manager.get_session),
) -> DatacenterState:
pass |
The fix transforms the example into from fastapi import Depends, FastAPI, APIRouter
from typing import Annotated
datacenter_state_router = APIRouter()
@datacenter_state_router.patch()
async def datacenter_state_patch(
current_state: DatacenterState = PermissionDepends(
Permission.WRITE, get_datacenter_state
),
session: Annotated[Session, Depends(database_manager.get_session)],
) -> DatacenterState:
pass and the problem is that The easiest fix is to disable the fix if the parameter comes after a parameter with a default value. |
MichaReiser
added
bug
Something isn't working
fixes
Related to suggested fixes for violations
preview
Related to preview mode features
good first issue
Good for newcomers
labels
Aug 19, 2024
arkuhn
added a commit
to arkuhn/ruff
that referenced
this issue
Aug 28, 2024
- Context: this rule swaps out default function argument values for type annotations - Problem: When this swap occurs after a default argument value is already present, the function signature is no longer valid python code (astral-sh#12982) - Fix: Track default arguments and bail if we hit this condition, making this fix only sometimes possible.
arkuhn
added a commit
to arkuhn/ruff
that referenced
this issue
Aug 28, 2024
- Context: this rule swaps out default function argument values for type annotations - Problem: When this swap occurs after a default argument value is already present, the function signature is no longer valid python code (astral-sh#12982) - Fix: Track default arguments and bail if we hit this condition, making this fix only sometimes possible.
arkuhn
added a commit
to arkuhn/ruff
that referenced
this issue
Aug 28, 2024
- Context: this rule swaps out default function argument values for type annotations - Problem: When this swap occurs after a default argument value is already present, the function signature is no longer valid python code (astral-sh#12982) - Fix: Track default arguments and bail if we hit this condition, making this fix only sometimes possible.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
fixes
Related to suggested fixes for violations
good first issue
Good for newcomers
preview
Related to preview mode features
Hello,
Using ruff 0.6.1, I keep getting an error on FAST002 autofix.
I tried to simplify as much as i could both the code and config
pyproject.toml
Removing that PermissionDepends arg (a wrapper around an actual dependency) fixes it.
The text was updated successfully, but these errors were encountered: