Skip to content

Commit 300aa7a

Browse files
authored
Tidy django.conf.urls (#2528)
1. Remove `url()`, [removed in Django 4.0](django/django@98ae392). 2. Import the default views rather than redefining their types. 3. Move `_IncludedURLConf` to `urls/conf.pyi`. 4. Copy `__all__` from [source](https://github.com/django/django/blob/main/django/conf/urls/__init__.py).
1 parent 29a5c32 commit 300aa7a

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed
Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
1-
from collections.abc import Callable, Sequence
2-
from typing import Any, overload
3-
4-
from django.http.response import HttpResponse, HttpResponseBase
5-
from django.urls import URLPattern, URLResolver
61
from django.urls import include as include
7-
from typing_extensions import TypeAlias
8-
9-
handler400: str | Callable[..., HttpResponse]
10-
handler403: str | Callable[..., HttpResponse]
11-
handler404: str | Callable[..., HttpResponse]
12-
handler500: str | Callable[..., HttpResponse]
2+
from django.views import defaults
133

14-
_IncludedURLConf: TypeAlias = tuple[Sequence[URLResolver | URLPattern], str | None, str | None]
4+
__all__ = ["handler400", "handler403", "handler404", "handler500", "include"]
155

16-
# Deprecated
17-
@overload
18-
def url(
19-
regex: str, view: Callable[..., HttpResponseBase], kwargs: dict[str, Any] | None = ..., name: str | None = ...
20-
) -> URLPattern: ...
21-
@overload
22-
def url(
23-
regex: str, view: _IncludedURLConf, kwargs: dict[str, Any] | None = ..., name: str | None = ...
24-
) -> URLResolver: ...
25-
@overload
26-
def url(
27-
regex: str,
28-
view: Sequence[URLResolver | str],
29-
kwargs: dict[str, Any] | None = ...,
30-
name: str | None = ...,
31-
) -> URLResolver: ...
6+
handler400 = defaults.bad_request
7+
handler403 = defaults.permission_denied
8+
handler404 = defaults.page_not_found
9+
handler500 = defaults.server_error

django-stubs/urls/conf.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ from django.urls import URLPattern, URLResolver, _AnyURL
66
from django.utils.functional import _StrOrPromise
77
from typing_extensions import TypeAlias
88

9-
from ..conf.urls import _IncludedURLConf
109
from ..http.response import HttpResponseBase
1110

1211
_URLConf: TypeAlias = str | ModuleType | Sequence[_AnyURL]
12+
_IncludedURLConf: TypeAlias = tuple[Sequence[URLResolver | URLPattern], str | None, str | None]
1313

1414
def include(arg: _URLConf | tuple[_URLConf, str], namespace: str | None = ...) -> _IncludedURLConf: ...
1515

scripts/stubtest/allowlist_todo.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
django.__main__
55
django.conf.global_settings.gettext_noop
6-
django.conf.urls.url
76
django.contrib.admin.FieldListFilter.title
87
django.contrib.admin.ModelAdmin
98
django.contrib.admin.StackedInline
@@ -1293,7 +1292,6 @@ django.db.backends.postgresql.base.Cursor
12931292

12941293
# mypy 1.14.0 new issues:
12951294
django.apps.__all__
1296-
django.conf.urls.__all__
12971295
django.contrib.admin.__all__
12981296
django.contrib.gis.admin.__all__
12991297
django.contrib.gis.db.models.__all__

0 commit comments

Comments
 (0)