Skip to content

Commit 5a34c13

Browse files
committed
Merge branch 'master' of https://github.com/FallenDeity/django-stubs into feat/builtin-models-types
2 parents 9e04be7 + 0be73eb commit 5a34c13

File tree

100 files changed

+643
-493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+643
-493
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
strategy:
2222
matrix:
23-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
23+
python-version: ['3.10', '3.11', '3.12', '3.13']
2424
fail-fast: false
2525
steps:
2626
- uses: actions/checkout@v4
@@ -48,7 +48,7 @@ jobs:
4848
runs-on: ubuntu-latest
4949
strategy:
5050
matrix:
51-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
51+
python-version: ['3.10', '3.11', '3.12', '3.13']
5252
shard: [0, 1, 2, 3]
5353
fail-fast: false
5454
steps:
@@ -132,13 +132,8 @@ jobs:
132132
strategy:
133133
fail-fast: false
134134
matrix:
135-
python-version: ['3.11', '3.12', '3.13']
136-
django-version: ['4.2', '5.0', '5.1']
137-
include:
138-
- python-version: '3.9'
139-
django-version: '4.2'
140-
- python-version: '3.10'
141-
django-version: '4.2'
135+
python-version: ['3.10', '3.11', '3.12', '3.13']
136+
django-version: ['5.0', '5.1', '5.2']
142137
steps:
143138
- uses: actions/checkout@v4
144139
- name: Setup system dependencies

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
args: [--fix=lf]
1818
- id: check-case-conflict
1919
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
rev: v0.11.2
20+
rev: v0.11.4
2121
hooks:
2222
- id: ruff
2323
args: ["--fix", "--exit-non-zero-on-fix"]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ This happens because these Django classes do not support [`__class_getitem__`](h
167167

168168
### How can I create a HttpRequest that's guaranteed to have an authenticated user?
169169

170-
Django's built in [`HttpRequest`](https://docs.djangoproject.com/en/4.1/ref/request-response/#django.http.HttpRequest) has the attribute `user` that resolves to the type
170+
Django's built in [`HttpRequest`](https://docs.djangoproject.com/en/5.2/ref/request-response/#django.http.HttpRequest) has the attribute `user` that resolves to the type
171171

172172
```python
173173
Union[User, AnonymousUser]
@@ -259,7 +259,7 @@ func(MyModel.objects.annotate(bar=Value("")).get(id=1)) # Error
259259

260260
The lazy translation functions of Django (such as `gettext_lazy`) return a `Promise` instead of `str`. These two types [cannot be used interchangeably](https://github.com/typeddjango/django-stubs/pull/1139#issuecomment-1232167698). The return type of these functions was therefore [changed](https://github.com/typeddjango/django-stubs/pull/689) to reflect that.
261261

262-
If you encounter this error in your own code, you can either cast the `Promise` to `str` (causing the translation to be evaluated), or use the `StrPromise` or `StrOrPromise` types from `django-stubs-ext` in type hints. Which solution to choose depends depends on the particular case. See [working with lazy translation objects](https://docs.djangoproject.com/en/4.1/topics/i18n/translation/#working-with-lazy-translation-objects) in the Django documentation for more information.
262+
If you encounter this error in your own code, you can either cast the `Promise` to `str` (causing the translation to be evaluated), or use the `StrPromise` or `StrOrPromise` types from `django-stubs-ext` in type hints. Which solution to choose depends depends on the particular case. See [working with lazy translation objects](https://docs.djangoproject.com/en/5.2/topics/i18n/translation/#working-with-lazy-translation-objects) in the Django documentation for more information.
263263

264264
If this is reported on Django code, please report an issue or open a pull request to fix the type hints.
265265

@@ -329,7 +329,7 @@ error: "type[Model]" has no attribute "objects" [attr-defined]
329329
```
330330

331331
It is a common problem: some `type[models.Model]` types won't have `.objects` available.
332-
Notable example: [abstract models](https://docs.djangoproject.com/en/5.1/topics/db/models/#abstract-base-classes).
332+
Notable example: [abstract models](https://docs.djangoproject.com/en/5.2/topics/db/models/#abstract-base-classes).
333333
See [the reasoning here](https://github.com/typeddjango/django-stubs/issues/1684).
334334

335335
So, instead for the general case you should write:

django-stubs/conf/global_settings.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ from re import Pattern
33

44
# This is defined here as a do-nothing function because we can't import
55
# django.utils.translation -- that module depends on the settings.
6-
from typing import Any, Literal, Protocol, type_check_only
7-
8-
from typing_extensions import TypeAlias
6+
from typing import Any, Literal, Protocol, TypeAlias, type_check_only
97

108
_Admins: TypeAlias = list[tuple[str, str]]
119

django-stubs/contrib/admin/options.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import enum
22
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
3-
from typing import Any, ClassVar, Generic, Literal, TypeVar, cast, overload, type_check_only
3+
from typing import Any, ClassVar, Generic, Literal, TypeAlias, TypeVar, cast, overload, type_check_only
44

55
from django import forms
66
from django.contrib.admin.filters import FieldListFilter, ListFilter
@@ -33,7 +33,7 @@ from django.urls.resolvers import URLPattern
3333
from django.utils.datastructures import _ListOrTuple
3434
from django.utils.functional import _StrOrPromise
3535
from django.utils.safestring import SafeString
36-
from typing_extensions import Self, TypeAlias, TypedDict, deprecated
36+
from typing_extensions import Self, TypedDict, deprecated
3737

3838
IS_POPUP_VAR: str
3939
TO_FIELD_VAR: str

django-stubs/contrib/admin/sites.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Callable, Iterable
2-
from typing import Any, TypeVar
2+
from typing import Any, TypeAlias, TypeVar
33
from weakref import WeakSet
44

55
from django.apps.config import AppConfig
@@ -14,7 +14,6 @@ from django.http.response import HttpResponse, HttpResponseBase
1414
from django.template.response import TemplateResponse
1515
from django.urls import URLPattern, URLResolver
1616
from django.utils.functional import LazyObject, _StrOrPromise
17-
from typing_extensions import TypeAlias
1817

1918
all_sites: WeakSet[AdminSite]
2019

django-stubs/contrib/auth/backends.pyi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1-
from typing import Any, TypeVar
1+
from typing import Any, TypeAlias, TypeVar
22

33
from django.contrib.auth.base_user import AbstractBaseUser, _UserModel
44
from django.contrib.auth.models import AnonymousUser, Permission
55
from django.db.models import QuerySet
66
from django.db.models.base import Model
77
from django.http.request import HttpRequest
8-
from typing_extensions import TypeAlias
98

109
UserModel: TypeAlias = type[_UserModel]
1110
_AnyUser: TypeAlias = _UserModel | AnonymousUser
1211

1312
class BaseBackend:
1413
def authenticate(self, request: HttpRequest | None, **kwargs: Any) -> _UserModel | None: ...
14+
async def aauthenticate(self, request: HttpRequest | None, **kwargs: Any) -> _UserModel | None: ...
1515
def get_user(self, user_id: Any) -> _UserModel | None: ...
16+
async def aget_user(self, user_id: Any) -> _UserModel | None: ...
1617
def get_user_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ...
18+
async def aget_user_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ...
1719
def get_group_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ...
20+
async def aget_group_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ...
1821
def get_all_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ...
22+
async def aget_all_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ...
1923
def has_perm(self, user_obj: _AnyUser, perm: str, obj: Model | None = ...) -> bool: ...
24+
async def ahas_perm(self, user_obj: _AnyUser, perm: str, obj: Model | None = ...) -> bool: ...
2025

2126
class ModelBackend(BaseBackend):
2227
def authenticate(
2328
self, request: HttpRequest | None, username: str | None = ..., password: str | None = ..., **kwargs: Any
2429
) -> _UserModel | None: ...
30+
async def aauthenticate(
31+
self, request: HttpRequest | None, username: str | None = ..., password: str | None = ..., **kwargs: Any
32+
) -> _UserModel | None: ...
2533
def has_module_perms(self, user_obj: _AnyUser, app_label: str) -> bool: ...
34+
async def ahas_module_perms(self, user_obj: _AnyUser, app_label: str) -> bool: ...
2635
def user_can_authenticate(self, user: _AnyUser | None) -> bool: ...
2736
def with_perm(
2837
self,

django-stubs/contrib/auth/base_user.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from collections.abc import Iterable
22
from datetime import date, datetime
3-
from typing import Any, ClassVar, Literal, TypeVar, overload
3+
from typing import Any, ClassVar, Literal, TypeAlias, TypeVar, overload
44

55
from django.db import models
66
from django.db.models.base import Model
77
from django.db.models.expressions import Combinable
88
from django.db.models.fields import BooleanField
9-
from typing_extensions import TypeAlias
109

1110
_T = TypeVar("_T", bound=Model)
1211

django-stubs/contrib/auth/forms.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Iterable
22
from logging import Logger
3-
from typing import Any, TypeVar
3+
from typing import Any, TypeAlias, TypeVar
44

55
from django import forms
66
from django.contrib.auth.base_user import AbstractBaseUser, _UserModel
@@ -12,7 +12,6 @@ from django.forms.fields import _ClassLevelWidgetT
1212
from django.forms.widgets import Widget
1313
from django.http.request import HttpRequest
1414
from django.utils.functional import _StrOrPromise
15-
from typing_extensions import TypeAlias
1615

1716
logger: Logger
1817

django-stubs/contrib/auth/middleware.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Callable, ClassVar
1+
from collections.abc import Callable
2+
from typing import Any, ClassVar
23

34
from django.contrib.auth.base_user import _UserModel
45
from django.contrib.auth.models import AnonymousUser

0 commit comments

Comments
 (0)