Skip to content

Ruff's ARG001 False Positive for an Endpoint w/o Usage of request #1458

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

Open
UnoYakshi opened this issue May 4, 2025 · 2 comments
Open

Ruff's ARG001 False Positive for an Endpoint w/o Usage of request #1458

UnoYakshi opened this issue May 4, 2025 · 2 comments

Comments

@UnoYakshi
Copy link

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()]
@vitalik
Copy link
Owner

vitalik commented May 5, 2025

@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]: 

@UnoYakshi
Copy link
Author

UnoYakshi commented May 14, 2025

@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'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants