From 7fabaced52b947d58f5b99ad53d3acc8a0b1e4c3 Mon Sep 17 00:00:00 2001 From: Petter Friberg Date: Tue, 4 Jun 2024 22:00:40 +0200 Subject: [PATCH] Remove generic argument of `django.db.models.lookups.Lookup` I might be missing something obvious here but I don't see what purpose the generic argument has or what it intends to control. --- django-stubs/db/models/lookups.pyi | 52 ++++++++++++++---------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/django-stubs/db/models/lookups.pyi b/django-stubs/db/models/lookups.pyi index f863ae8ac..71f29054f 100644 --- a/django-stubs/db/models/lookups.pyi +++ b/django-stubs/db/models/lookups.pyi @@ -1,5 +1,5 @@ from collections.abc import Iterable -from typing import Any, Generic, Literal, Sequence, TypeVar +from typing import Any, Literal, Sequence from django.core.exceptions import EmptyResultSet from django.db.backends.base.base import BaseDatabaseWrapper @@ -10,9 +10,7 @@ from django.db.models.sql.compiler import SQLCompiler, _AsSqlType, _ParamT from django.utils.datastructures import OrderedSet from django.utils.functional import cached_property -_T = TypeVar("_T") - -class Lookup(Expression, Generic[_T]): +class Lookup(Expression): lookup_name: str prepare_rhs: bool can_use_none_as_rhs: bool @@ -50,7 +48,7 @@ class Transform(RegisterLookupMixin, Func): def lhs(self) -> Expression: ... def get_bilateral_transforms(self) -> list[type[Transform]]: ... -class BuiltinLookup(Lookup[_T]): +class BuiltinLookup(Lookup): def process_lhs( self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, lhs: Expression | None = ... ) -> _AsSqlType: ... @@ -67,16 +65,16 @@ class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin): self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, sql: str, param: Any ) -> _AsSqlType: ... -class PostgresOperatorLookup(Lookup[_T]): +class PostgresOperatorLookup(Lookup): postgres_operator: str | None def as_postgresql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... -class Exact(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... -class IExact(BuiltinLookup[_T]): ... -class GreaterThan(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... -class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... -class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... -class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ... +class Exact(FieldGetDbPrepValueMixin, BuiltinLookup): ... +class IExact(BuiltinLookup): ... +class GreaterThan(FieldGetDbPrepValueMixin, BuiltinLookup): ... +class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup): ... +class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup): ... +class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup): ... class IntegerFieldOverflow: underflow_exception: type[EmptyResultSet] @@ -87,16 +85,16 @@ class IntegerFieldFloatRounding: rhs: Any def get_prep_lookup(self) -> Any: ... -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 IntegerFieldExact(IntegerFieldOverflow, Exact): ... +class IntegerGreaterThan(IntegerFieldOverflow, GreaterThan): ... +class IntegerGreaterThanOrEqual(IntegerFieldOverflow, IntegerFieldFloatRounding, GreaterThanOrEqual): ... +class IntegerLessThan(IntegerFieldOverflow, IntegerFieldFloatRounding, LessThan): ... +class IntegerLessThanOrEqual(IntegerFieldOverflow, LessThanOrEqual): ... class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup): def split_parameter_list_as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> Any: ... -class PatternLookup(BuiltinLookup[str]): +class PatternLookup(BuiltinLookup): param_pattern: str class Contains(PatternLookup): ... @@ -105,9 +103,9 @@ class StartsWith(PatternLookup): ... class IStartsWith(StartsWith): ... class EndsWith(PatternLookup): ... class IEndsWith(EndsWith): ... -class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup[_T]): ... -class IsNull(BuiltinLookup[bool]): ... -class Regex(BuiltinLookup[str]): ... +class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup): ... +class IsNull(BuiltinLookup): ... +class Regex(BuiltinLookup): ... class IRegex(Regex): ... class YearLookup(Lookup): @@ -115,26 +113,26 @@ class YearLookup(Lookup): def get_direct_rhs_sql(self, connection: BaseDatabaseWrapper, rhs: str) -> str: ... def get_bound_params(self, start: Any, finish: Any) -> Any: ... -class YearExact(YearLookup, Exact[_T]): +class YearExact(YearLookup, Exact): def get_bound_params(self, start: Any, finish: Any) -> tuple[Any, Any]: ... -class YearGt(YearLookup, GreaterThan[_T]): +class YearGt(YearLookup, GreaterThan): def get_bound_params(self, start: Any, finish: Any) -> tuple[Any]: ... -class YearGte(YearLookup, GreaterThanOrEqual[_T]): +class YearGte(YearLookup, GreaterThanOrEqual): def get_bound_params(self, start: Any, finish: Any) -> tuple[Any]: ... -class YearLt(YearLookup, LessThan[_T]): +class YearLt(YearLookup, LessThan): def get_bound_params(self, start: Any, finish: Any) -> tuple[Any]: ... -class YearLte(YearLookup, LessThanOrEqual[_T]): +class YearLte(YearLookup, LessThanOrEqual): def get_bound_params(self, start: Any, finish: Any) -> tuple[Any]: ... class UUIDTextMixin: rhs: Any def process_rhs(self, qn: Any, connection: BaseDatabaseWrapper) -> Any: ... -class UUIDIExact(UUIDTextMixin, IExact[_T]): ... +class UUIDIExact(UUIDTextMixin, IExact): ... class UUIDContains(UUIDTextMixin, Contains): ... class UUIDIContains(UUIDTextMixin, IContains): ... class UUIDStartsWith(UUIDTextMixin, StartsWith): ...