Skip to content

Commit b1b0502

Browse files
Fix missing at runtime errors (second batch) (#2636)
* `LogoutView.get_next_page` renamed to `get_success_url` in 4.1 * Removed in 5.2 (`create_spatial_indexes`) * Remove `admin_list.DOT` symbol * Remove `INTERNAL_RESET_URL_TOKEN` * Remove `PostGISAdapter.prepare` Removed in 4.2 https://github.com/django/django/blob/stable/4.2.x/django/contrib/gis/db/backends/postgis/adapter.py * QuerySet does not implement `__reversed__` AttributeError: 'QuerySet' object has no attribute '__reversed__' * Fix `psycopg2_version` types * InvalidQuery removed in 4.0 * The ``django.db.models.query_utils.InvalidQuery`` exception class is removed. * `save_m2m` is dynamically added on modelforms * Remove ifequal nodes * MultiColSource removed in django 5.2
1 parent 69d40e2 commit b1b0502

File tree

12 files changed

+12
-78
lines changed

12 files changed

+12
-78
lines changed

django-stubs/contrib/admin/templatetags/admin_list.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ from django.utils.safestring import SafeString
1313
from .base import InclusionAdminNode
1414

1515
register: Any
16-
DOT: str
1716

1817
def paginator_number(cl: ChangeList, i: int) -> SafeString: ...
1918
def pagination(cl: ChangeList) -> dict[str, Any]: ...

django-stubs/contrib/auth/views.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class LogoutView(RedirectURLMixin, TemplateView):
3131
extra_context: Any
3232
def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
3333
def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
34-
def get_next_page(self) -> str | None: ...
3534

3635
def logout_then_login(request: HttpRequest, login_url: str | None = ...) -> HttpResponseRedirect: ...
3736
def redirect_to_login(
@@ -51,7 +50,6 @@ class PasswordResetView(PasswordContextMixin, FormView):
5150
title: Any
5251
token_generator: Any
5352

54-
INTERNAL_RESET_URL_TOKEN: str
5553
INTERNAL_RESET_SESSION_TOKEN: str
5654

5755
class PasswordResetDoneView(PasswordContextMixin, TemplateView):

django-stubs/contrib/gis/db/backends/mysql/schema.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ class MySQLGISSchemaEditor(DatabaseSchemaEditor):
1919
def create_model(self, model: type[Model]) -> None: ...
2020
def add_field(self, model: type[Model], field: Field) -> None: ...
2121
def remove_field(self, model: type[Model], field: Field) -> None: ...
22-
def create_spatial_indexes(self) -> None: ...

django-stubs/contrib/gis/db/backends/postgis/adapter.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ class PostGISAdapter:
99
def __conform__(self, proto: Any) -> Any: ...
1010
def __eq__(self, other: object) -> bool: ...
1111
def __hash__(self) -> int: ...
12-
def prepare(self, conn: Any) -> None: ...
1312
def getquoted(self) -> Any: ...

django-stubs/db/backends/postgresql/base.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ from .features import DatabaseFeatures
1212
from .introspection import DatabaseIntrospection
1313
from .operations import DatabaseOperations
1414

15-
def psycopg2_version() -> tuple[int, ...]: ...
16-
17-
PSYCOPG2_VERSION: tuple[int, ...]
15+
def psycopg_version() -> tuple[int, int, int]: ...
1816

1917
class DatabaseWrapper(BaseDatabaseWrapper):
2018
client: DatabaseClient

django-stubs/db/models/fields/related_lookups.pyi

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
1-
from collections.abc import Iterable, Mapping
1+
from collections.abc import Iterable
22
from typing import Any
33

4-
from django.db.models.fields import Field
5-
from django.db.models.lookups import (
6-
Exact,
7-
GreaterThan,
8-
GreaterThanOrEqual,
9-
In,
10-
IsNull,
11-
LessThan,
12-
LessThanOrEqual,
13-
Lookup,
14-
)
15-
16-
class MultiColSource:
17-
alias: str
18-
field: Field
19-
sources: tuple[Field, Field]
20-
targets: tuple[Field, Field]
21-
contains_aggregate: bool
22-
output_field: Field
23-
def __init__(
24-
self, alias: str, targets: tuple[Field, Field], sources: tuple[Field, Field], field: Field
25-
) -> None: ...
26-
def relabeled_clone(self, relabels: Mapping[str, str]) -> MultiColSource: ...
27-
def get_lookup(self, lookup: str) -> type[Lookup] | None: ...
4+
from django.db.models.lookups import Exact, GreaterThan, GreaterThanOrEqual, In, IsNull, LessThan, LessThanOrEqual
285

296
def get_normalized_value(value: Any, lhs: Any) -> tuple[Any, ...]: ...
307

django-stubs/db/models/query.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ class QuerySet(Generic[_Model, _Row], Iterable[_Row], Sized):
192192
def __getitem__(self, i: int) -> _Row: ...
193193
@overload
194194
def __getitem__(self, s: slice) -> Self: ...
195-
def __reversed__(self) -> Iterator[_Row]: ...
196195

197196
class RawQuerySet(Iterable[_Model], Sized):
198197
query: RawQuery

django-stubs/db/models/query_utils.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ PathInfo = namedtuple(
1919
"PathInfo", ["from_opts", "to_opts", "target_fields", "join_field", "m2m", "direct", "filtered_relation"]
2020
)
2121

22-
class InvalidQuery(Exception): ...
23-
2422
def subclasses(cls: type[RegisterLookupMixin]) -> Iterator[type[RegisterLookupMixin]]: ...
2523

2624
class Q(tree.Node):

django-stubs/template/defaulttags.pyi

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,6 @@ class IfChangedNode(Node):
6565
child_nodelists: Any
6666
def __init__(self, nodelist_true: NodeList, nodelist_false: NodeList, *varlist: Any) -> None: ...
6767

68-
class IfEqualNode(Node):
69-
nodelist_false: list[Any] | NodeList
70-
nodelist_true: list[Any] | NodeList
71-
var1: FilterExpression | str
72-
var2: FilterExpression | str
73-
child_nodelists: Any
74-
negate: bool
75-
def __init__(
76-
self,
77-
var1: FilterExpression | str,
78-
var2: FilterExpression | str,
79-
nodelist_true: list[Any] | NodeList,
80-
nodelist_false: list[Any] | NodeList,
81-
negate: bool,
82-
) -> None: ...
83-
8468
class IfNode(Node):
8569
conditions_nodelists: list[tuple[TemplateLiteral | None, NodeList]]
8670
def __init__(self, conditions_nodelists: list[tuple[TemplateLiteral | None, NodeList]]) -> None: ...
@@ -172,9 +156,6 @@ def debug(parser: Parser, token: Token) -> DebugNode: ...
172156
def do_filter(parser: Parser, token: Token) -> FilterNode: ...
173157
def firstof(parser: Parser, token: Token) -> FirstOfNode: ...
174158
def do_for(parser: Parser, token: Token) -> ForNode: ...
175-
def do_ifequal(parser: Parser, token: Token, negate: bool) -> IfEqualNode: ...
176-
def ifequal(parser: Parser, token: Token) -> IfEqualNode: ...
177-
def ifnotequal(parser: Parser, token: Token) -> IfEqualNode: ...
178159

179160
class TemplateLiteral(Literal):
180161
text: str

scripts/stubtest/allowlist.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,12 @@ django.db.models.fields.generated.GeneratedField.__init__
538538
# https://github.com/python/cpython/blob/5abff6960b4aecb0d5c81c7482cf3faa74e1983d/Lib/copyreg.py#L112-L161
539539
# Some Django classes get copied at import time, which leads stubtest to detect it.
540540
.*\.__slotnames__
541+
542+
# These are dynamically added when using `save(commit=False)`
543+
# See https://docs.djangoproject.com/en/5.2/topics/forms/modelforms/#the-save-method
544+
django.forms.BaseModelForm.save_m2m
545+
django.forms.BaseModelFormSet.save_m2m
546+
django.forms.models.BaseModelForm.save_m2m
547+
django.forms.models.BaseModelFormSet.save_m2m
548+
django.contrib.gis.forms.BaseModelForm.save_m2m
549+
django.contrib.gis.forms.BaseModelFormSet.save_m2m

0 commit comments

Comments
 (0)