Skip to content
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

Fix annotation for request.auser #2108

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions django-stubs/http/request.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import datetime
from collections.abc import Iterable, Mapping
from io import BytesIO
from re import Pattern
from typing import Any, BinaryIO, Callable, Literal, NoReturn, TypeVar, overload, type_check_only
from typing import Any, Awaitable, BinaryIO, Callable, Literal, NoReturn, TypeVar, overload, type_check_only

from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import AnonymousUser
Expand Down Expand Up @@ -57,7 +57,7 @@ class HttpRequest(BytesIO):
# django.contrib.auth.middleware.AuthenticationMiddleware:
user: AbstractBaseUser | AnonymousUser
# django.contrib.auth.middleware.AuthenticationMiddleware:
auser: Callable[[], AbstractBaseUser | AnonymousUser]
auser: Callable[[], Awaitable[AbstractBaseUser | AnonymousUser]]
# django.middleware.locale.LocaleMiddleware:
LANGUAGE_CODE: str
# django.contrib.sites.middleware.CurrentSiteMiddleware
Expand Down
12 changes: 12 additions & 0 deletions tests/typecheck/test_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,15 @@
reveal_type(req.GET) # N: Revealed type is "django.http.request._ImmutableQueryDict"
req.GET['foo'] = 'bar' # E: This QueryDict is immutable. [misc]
x = 1 # E: Statement is unreachable [unreachable]

- case: request_user_auser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for it, but I don't think we need this test. The change is simple enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, i see my test broke the pipeline. I removed test

main: |
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import AnonymousUser
from django.http.request import HttpRequest

async def get_user_async(request: HttpRequest) -> AbstractBaseUser | AnonymousUser:
return await request.auser()

def get_user_sync(request: HttpRequest) -> AbstractBaseUser | AnonymousUser:
return request.user
Loading