Skip to content

Commit 054cdd4

Browse files
bigfootjonintgr
andauthored
[5.0] Added many new a-prefixed asynchronous methods (#1741)
* Asyncify auth funcs + methods in test Client django/django@5e98959 * Fixed #34565 -- Added support for async checking of user passwords. django/django@674c239 * Fixed #34714 -- Added aget_object_or_404()/aget_list_or_404() shortcuts. django/django@b9473ca * Fixed #34331 -- Added QuerySet.aiterator() support for prefetch_related(). django/django@fff1473 * Update stubtest ignores --------- Co-authored-by: Marti Raudsepp <[email protected]>
1 parent a0eb714 commit 054cdd4

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

django-stubs/contrib/auth/__init__.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ REDIRECT_FIELD_NAME: str
1919
def load_backend(path: str) -> ModelBackend: ...
2020
def get_backends() -> list[ModelBackend]: ...
2121
def authenticate(request: HttpRequest | None = ..., **credentials: Any) -> AbstractBaseUser | None: ...
22+
async def aauthenticate(request: HttpRequest | None = ..., **credentials: Any) -> AbstractBaseUser | None: ...
2223
def login(
2324
request: HttpRequest, user: AbstractBaseUser | None, backend: type[ModelBackend] | str | None = ...
2425
) -> None: ...
26+
async def alogin(
27+
request: HttpRequest, user: AbstractBaseUser | None, backend: type[ModelBackend] | str | None = ...
28+
) -> None: ...
2529
def logout(request: HttpRequest) -> None: ...
30+
async def alogout(request: HttpRequest) -> None: ...
2631
def get_user_model() -> type[AbstractBaseUser]: ...
2732
def get_user(request: HttpRequest | Client) -> AbstractBaseUser | AnonymousUser: ...
33+
async def aget_user(request: HttpRequest | Client) -> AbstractBaseUser | AnonymousUser: ...
2834
def get_permission_codename(action: str, opts: Options) -> str: ...
2935
def update_session_auth_hash(request: HttpRequest, user: AbstractBaseUser) -> None: ...
36+
async def aupdate_session_auth_hash(request: HttpRequest, user: AbstractBaseUser) -> None: ...
3037

3138
default_app_config: str

django-stubs/contrib/auth/base_user.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AbstractBaseUser(models.Model):
3030
def is_authenticated(self) -> Literal[True]: ...
3131
def set_password(self, raw_password: str | None) -> None: ...
3232
def check_password(self, raw_password: str) -> bool: ...
33+
async def acheck_password(self, raw_password: str) -> bool: ...
3334
def set_unusable_password(self) -> None: ...
3435
def has_usable_password(self) -> bool: ...
3536
def get_session_auth_hash(self) -> str: ...

django-stubs/contrib/auth/hashers.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ UNUSABLE_PASSWORD_SUFFIX_LENGTH: int
66

77
def is_password_usable(encoded: str | None) -> bool: ...
88
def check_password(password: str | None, encoded: str, setter: Callable | None = ..., preferred: str = ...) -> bool: ...
9+
async def acheck_password(
10+
password: str | None, encoded: str, setter: Callable | None = ..., preferred: str = ...
11+
) -> bool: ...
912
def make_password(password: str | None, salt: str | None = ..., hasher: str | BasePasswordHasher = ...) -> str: ...
1013
def get_hashers() -> list[BasePasswordHasher]: ...
1114
def get_hashers_by_algorithm() -> dict[str, BasePasswordHasher]: ...

django-stubs/db/models/query.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class Prefetch:
234234
def get_current_queryset(self, level: int) -> QuerySet | None: ...
235235

236236
def prefetch_related_objects(model_instances: Iterable[_T], *related_lookups: str | Prefetch) -> None: ...
237+
async def aprefetch_related_objects(model_instances: Iterable[_T], *related_lookups: str | Prefetch) -> None: ...
237238
def get_prefetcher(instance: Model, through_attr: str, to_attr: str) -> tuple[Any, Any, bool, bool]: ...
238239

239240
class InstanceCheckMeta(type): ...

django-stubs/shortcuts.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ def redirect(
3434
_T = TypeVar("_T", bound=Model)
3535

3636
def get_object_or_404(klass: type[_T] | Manager[_T] | QuerySet[_T], *args: Any, **kwargs: Any) -> _T: ...
37+
async def aget_object_or_404(klass: type[_T] | Manager[_T] | QuerySet[_T], *args: Any, **kwargs: Any) -> _T: ...
3738
def get_list_or_404(klass: type[_T] | Manager[_T] | QuerySet[_T], *args: Any, **kwargs: Any) -> list[_T]: ...
39+
async def aget_list_or_404(klass: type[_T] | Manager[_T] | QuerySet[_T], *args: Any, **kwargs: Any) -> list[_T]: ...
3840
def resolve_url(to: Callable | Model | str, *args: Any, **kwargs: Any) -> str: ...

django-stubs/test/client.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,13 @@ class ClientMixin:
180180
def check_exception(self, response: HttpResponseBase) -> NoReturn: ...
181181
@property
182182
def session(self) -> SessionBase: ...
183+
async def asession(self) -> SessionBase: ...
183184
def login(self, **credentials: Any) -> bool: ...
185+
async def alogin(self, **credentials: Any) -> bool: ...
184186
def force_login(self, user: AbstractBaseUser, backend: str | None = ...) -> None: ...
187+
async def aforce_login(self, user: AbstractBaseUser, backend: str | None = ...) -> None: ...
185188
def logout(self) -> None: ...
189+
async def alogout(self) -> None: ...
186190

187191
class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
188192
handler: ClientHandler

scripts/stubtest/allowlist_todo_django50.txt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,10 @@ django.contrib.admin.sites.AdminSite.get_model_admin
4040
django.contrib.admin.utils.build_q_object_from_lookup_parameters
4141
django.contrib.admin.utils.get_last_value_from_parameters
4242
django.contrib.admin.views.main.ChangeList.get_queryset
43-
django.contrib.auth.aauthenticate
4443
django.contrib.auth.admin.UserAdmin.lookup_allowed
45-
django.contrib.auth.aget_user
46-
django.contrib.auth.alogin
47-
django.contrib.auth.alogout
48-
django.contrib.auth.aupdate_session_auth_hash
49-
django.contrib.auth.base_user.AbstractBaseUser.acheck_password
5044
django.contrib.auth.hashers.CryptPasswordHasher
51-
django.contrib.auth.hashers.acheck_password
5245
django.contrib.auth.hashers.verify_password
5346
django.contrib.auth.middleware.auser
54-
django.contrib.auth.models.AbstractBaseUser.acheck_password
5547
django.contrib.contenttypes.fields.GenericForeignKey.get_content_type
5648
django.contrib.contenttypes.fields.GenericForeignKey.get_prefetch_querysets
5749
django.contrib.contenttypes.prefetch
@@ -242,7 +234,6 @@ django.db.models.lookups.Lookup.allowed_default
242234
django.db.models.query.Prefetch.get_current_querysets
243235
django.db.models.query.QuerySet.aupdate_or_create
244236
django.db.models.query.QuerySet.update_or_create
245-
django.db.models.query.aprefetch_related_objects
246237
django.db.models.query_utils.FilteredRelation.relabeled_clone
247238
django.db.models.query_utils.FilteredRelation.resolve_expression
248239
django.db.models.query_utils.Q.identity
@@ -278,8 +269,6 @@ django.forms.renderers.BaseRenderer.field_template_name
278269
django.forms.renderers.Jinja2DivFormRenderer.__init__
279270
django.forms.utils.RenderableFieldMixin
280271
django.forms.widgets.ClearableFileInput.checked
281-
django.shortcuts.aget_list_or_404
282-
django.shortcuts.aget_object_or_404
283272
django.template.Template.__iter__
284273
django.template.autoreload
285274
django.template.base.Template.__iter__
@@ -300,10 +289,6 @@ django.test.client.AsyncClient.patch
300289
django.test.client.AsyncClient.post
301290
django.test.client.AsyncClient.put
302291
django.test.client.AsyncClient.trace
303-
django.test.client.ClientMixin.aforce_login
304-
django.test.client.ClientMixin.alogin
305-
django.test.client.ClientMixin.alogout
306-
django.test.client.ClientMixin.asession
307292
django.test.runner.DiscoverRunner.__init__
308293
django.test.runner.DiscoverRunner.run_tests
309294
django.test.runner.RemoteTestResult.addDuration

0 commit comments

Comments
 (0)