From 29f03bf0c035f751467d21c8d7a3ae84fa5cd6ec Mon Sep 17 00:00:00 2001 From: SaJH Date: Wed, 1 May 2024 01:52:59 +0900 Subject: [PATCH 1/2] 5.0: Update django.db.models.lookups --- django-stubs/db/models/lookups.pyi | 12 ++++++++++-- scripts/stubtest/allowlist_todo_django50.txt | 6 ------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/django-stubs/db/models/lookups.pyi b/django-stubs/db/models/lookups.pyi index d7462f4d9..bd91e3757 100644 --- a/django-stubs/db/models/lookups.pyi +++ b/django-stubs/db/models/lookups.pyi @@ -82,12 +82,20 @@ class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... +class IntegerFieldOverflow: + underflow_exception: type[Exception] + overflow_exception: type[Exception] + def process_rhs(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... + class IntegerFieldFloatRounding: rhs: Any def get_prep_lookup(self) -> Any: ... -class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual[int | float]): ... -class IntegerLessThan(IntegerFieldFloatRounding, LessThan[int | float]): ... +class IntegerFieldExact(IntegerFieldOverflow, Exact[int | float]): ... +class IntegerGreaterThan(IntegerFieldOverflow, GreaterThan[int | float]): ... +class IntegerGreaterThanOrEqual(IntegerFieldOverflow, IntegerFieldFloatRounding, GreaterThanOrEqual[int | float]): ... +class IntegerLessThan(IntegerFieldOverflow, IntegerFieldFloatRounding, LessThan[int | float]): ... +class IntegerLessThanOrEqual(IntegerFieldOverflow, LessThanOrEqual[int | float]): ... class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup): def split_parameter_list_as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> Any: ... diff --git a/scripts/stubtest/allowlist_todo_django50.txt b/scripts/stubtest/allowlist_todo_django50.txt index e1d9d6ed0..8be179b86 100644 --- a/scripts/stubtest/allowlist_todo_django50.txt +++ b/scripts/stubtest/allowlist_todo_django50.txt @@ -124,12 +124,6 @@ django.db.models.functions.Collate.allowed_default django.db.models.functions.Now.as_oracle django.db.models.functions.comparison.Collate.allowed_default django.db.models.functions.datetime.Now.as_oracle -django.db.models.lookups.IntegerFieldExact -django.db.models.lookups.IntegerFieldOverflow -django.db.models.lookups.IntegerGreaterThan -django.db.models.lookups.IntegerGreaterThanOrEqual.underflow_exception -django.db.models.lookups.IntegerLessThan.overflow_exception -django.db.models.lookups.IntegerLessThanOrEqual django.db.models.lookups.Lookup.allowed_default django.db.models.query.Prefetch.get_current_querysets django.db.models.query_utils.FilteredRelation.relabeled_clone From f4bde9ab209e3245695ba34bdcb57c6b6b8301e8 Mon Sep 17 00:00:00 2001 From: SaJH Date: Wed, 1 May 2024 16:36:45 +0900 Subject: [PATCH 2/2] Fix by providing the exact type of exception --- django-stubs/db/models/lookups.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/django-stubs/db/models/lookups.pyi b/django-stubs/db/models/lookups.pyi index bd91e3757..3b667fdd5 100644 --- a/django-stubs/db/models/lookups.pyi +++ b/django-stubs/db/models/lookups.pyi @@ -1,6 +1,7 @@ from collections.abc import Iterable, Mapping from typing import Any, Generic, Literal, TypeVar +from django.core.exceptions import EmptyResultSet from django.db.backends.base.base import BaseDatabaseWrapper from django.db.models.expressions import Expression, Func from django.db.models.fields import BooleanField @@ -83,8 +84,8 @@ class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... class IntegerFieldOverflow: - underflow_exception: type[Exception] - overflow_exception: type[Exception] + underflow_exception: type[EmptyResultSet] + overflow_exception: type[EmptyResultSet] def process_rhs(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... class IntegerFieldFloatRounding: