django-ninja
django-ninja copied to clipboard
Ruff's `ARG001` False Positive for an Endpoint w/o Usage of `request`
In an endpoint with explicitly unused request argument, Ruff triggers ARG001. One of the member asked me to open an issue in Django-Ninja to check if it's possible or not (figuratively) to make request argument optional.
For more detailed context, please, refer to the Ruff issue.
# Imports and stuff...
@router.get('/', response=list[UserSchema])
def get_users(request: HttpRequest) -> list[UserSchema]: # Triggers ARG001!
"""Retrieve all Users..."""
return [UserSchema.from_orm(user) for user in BaseUser.objects.all()]
@UnoYakshi - long story short - no - cannot make it optional - we try to be as much similar to django views where request is always passed to view function (lot of 3rd party apps/plugins/decorators depend on it)
what you can try is adding _:
def get_users(_request: HttpRequest) -> list[UserSchema]:
@vitalik, I immediately (when I launch Django app) get
NameError: Fields must not use names with leading underscores; e.g., use 'request' instead of '_request'.
Got into the same problem, don't know how to fix it elegantly