Closed mbrulatout closed 2 weeks ago
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 session
now no longer has a default value but comes after a parameter with a default value.
The easiest fix is to disable the fix if the parameter comes after a parameter with a default value.
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.