Skip to content

[FAST002] FastAPI dependency without Annotated unsafe fix error #12982

@mbrulatout

Description

@mbrulatout

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

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

pyproject.toml

[tool.ruff]
target-version = 'py311'
line-length = 120
exclude = [
    "criteo/ingress/api/lib/models/alembic/"
]

[tool.ruff.format]
preview = true

[tool.ruff.lint]
# See complete list : https://beta.ruff.rs/docs/rules
select = [
    "FAST",  # fastapi
]

fixable = [
    "FAST002",
]

Removing that PermissionDepends arg (a wrapper around an actual dependency) fixes it.

class Permission(Enum):
    READ = "read"
    WRITE = "write"

def permission_dependency(
    permission: Permission, resource: Callable[..., Any], user: User = Depends(get_current_user)
) -> Any:
    dependable_resource = Depends(resource)

    def resource_call(_resource: OwnedResource = dependable_resource, _user: User = user) -> Any:
        return _resource

    return Depends(resource_call)

# An alias to mimic FastAPI Dependency (https://fastapi.tiangolo.com/reference/dependencies/#fastapi.Depends)
# This is usable with the additional permission, the contract being the following:
# PermissionDepends(Permission, Callable[..., OwnedResource])
PermissionDepends = permission_dependency

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationsgood first issueGood for newcomerspreviewRelated to preview mode features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions