From e8d03a0e22c05a951d1750e829af8905c90f925f Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Thu, 13 May 2021 13:38:08 +0300 Subject: [PATCH] Use BaseDatabaseWrapper class instead of sqlite3's wrapper (#610) Code dealing with DatabaseWrapper instances should be capable of dealing with any database, not just sqlite3. --- django-stubs/db/models/functions/text.pyi | 4 ++-- django-stubs/db/models/lookups.pyi | 18 +++++++++--------- django-stubs/db/models/options.pyi | 4 ++-- django-stubs/test/testcases.pyi | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/django-stubs/db/models/functions/text.pyi b/django-stubs/db/models/functions/text.pyi index fc120a4..a2e757c 100644 --- a/django-stubs/db/models/functions/text.pyi +++ b/django-stubs/db/models/functions/text.pyi @@ -1,6 +1,6 @@ from typing import Any, List, Optional, Tuple, Union -from django.db.backends.sqlite3.base import DatabaseWrapper +from django.db.backends.base.base import BaseDatabaseWrapper from django.db.models.expressions import Combinable, Expression, Value from django.db.models.sql.compiler import SQLCompiler @@ -18,7 +18,7 @@ class Left(Func): def __init__(self, expression: str, length: Union[Value, int], **extra: Any) -> None: ... def get_substr(self) -> Substr: ... def use_substr( - self, compiler: SQLCompiler, connection: DatabaseWrapper, **extra_context: Any + self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any ) -> Tuple[str, List[int]]: ... class Length(Transform): ... diff --git a/django-stubs/db/models/lookups.pyi b/django-stubs/db/models/lookups.pyi index ca9ab66..58040ed 100644 --- a/django-stubs/db/models/lookups.pyi +++ b/django-stubs/db/models/lookups.pyi @@ -1,7 +1,7 @@ from datetime import datetime from typing import Any, Iterable, List, Optional, Tuple, Type, Union, Mapping, TypeVar, Generic -from django.db.backends.sqlite3.base import DatabaseWrapper +from django.db.backends.base.base import BaseDatabaseWrapper from django.db.models.expressions import Expression, Func from django.db.models.query_utils import RegisterLookupMixin from django.db.models.sql.compiler import SQLCompiler @@ -22,16 +22,16 @@ class Lookup(Generic[_T]): def __init__(self, lhs: Union[Expression, TextField, related_lookups.MultiColSource], rhs: Any) -> None: ... def apply_bilateral_transforms(self, value: Expression) -> Transform: ... def batch_process_rhs( - self, compiler: SQLCompiler, connection: DatabaseWrapper, rhs: Optional[OrderedSet] = ... + self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, rhs: Optional[OrderedSet] = ... ) -> Tuple[List[str], List[str]]: ... def get_source_expressions(self) -> List[Expression]: ... def set_source_expressions(self, new_exprs: List[Expression]) -> None: ... def get_prep_lookup(self) -> Any: ... - def get_db_prep_lookup(self, value: Union[int, str], connection: DatabaseWrapper) -> Tuple[str, List[SafeText]]: ... + def get_db_prep_lookup(self, value: Union[int, str], connection: BaseDatabaseWrapper) -> Tuple[str, List[SafeText]]: ... def process_lhs( - self, compiler: SQLCompiler, connection: DatabaseWrapper, lhs: Optional[Expression] = ... + self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, lhs: Optional[Expression] = ... ) -> Tuple[str, List[Union[int, str]]]: ... - def process_rhs(self, compiler: SQLCompiler, connection: DatabaseWrapper) -> Tuple[str, List[Union[int, str]]]: ... + def process_rhs(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> Tuple[str, List[Union[int, str]]]: ... def rhs_is_direct_value(self) -> bool: ... def relabeled_clone(self: _T, relabels: Mapping[str, str]) -> _T: ... def get_group_by_cols(self) -> List[Expression]: ... @@ -48,7 +48,7 @@ class Transform(RegisterLookupMixin, Func): def get_bilateral_transforms(self) -> List[Type[Transform]]: ... class BuiltinLookup(Lookup[_T]): - def get_rhs_op(self, connection: DatabaseWrapper, rhs: str) -> str: ... + def get_rhs_op(self, connection: BaseDatabaseWrapper, rhs: str) -> str: ... class FieldGetDbPrepValueMixin: get_db_prep_lookup_value_is_iterable: bool = ... @@ -56,7 +56,7 @@ class FieldGetDbPrepValueMixin: class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin): def get_prep_lookup(self) -> Iterable[Any]: ... def resolve_expression_parameter( - self, compiler: SQLCompiler, connection: DatabaseWrapper, sql: str, param: Any + self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, sql: str, param: Any ) -> Any: ... class PostgresOperatorLookup(FieldGetDbPrepValueMixin, Lookup): @@ -95,10 +95,10 @@ class Regex(BuiltinLookup[str]): ... class IRegex(Regex): ... class YearLookup(Lookup): - def year_lookup_bounds(self, connection: DatabaseWrapper, year: int) -> List[str]: ... + def year_lookup_bounds(self, connection: BaseDatabaseWrapper, year: int) -> List[str]: ... class YearComparisonLookup(YearLookup): - def get_rhs_op(self, connection: DatabaseWrapper, rhs: str) -> str: ... + def get_rhs_op(self, connection: BaseDatabaseWrapper, rhs: str) -> str: ... def get_bound(self, start: datetime, finish: datetime) -> Any: ... class YearExact(YearLookup, Exact): ... diff --git a/django-stubs/db/models/options.pyi b/django-stubs/db/models/options.pyi index d7fee81..4a4f903 100644 --- a/django-stubs/db/models/options.pyi +++ b/django-stubs/db/models/options.pyi @@ -6,7 +6,7 @@ from django.apps.registry import Apps from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.postgres.fields.array import ArrayField from django.contrib.postgres.fields.citext import CIText -from django.db.backends.sqlite3.base import DatabaseWrapper +from django.db.backends.base.base import BaseDatabaseWrapper from django.db.models.base import Model from django.db.models.constraints import BaseConstraint from django.db.models.fields.mixins import FieldCacheMixin @@ -97,7 +97,7 @@ class Options(Generic[_M]): def add_field(self, field: Union[GenericForeignKey, Field], private: bool = ...) -> None: ... def setup_pk(self, field: Field) -> None: ... def setup_proxy(self, target: Type[Model]) -> None: ... - def can_migrate(self, connection: Union[DatabaseWrapper, str]) -> bool: ... + def can_migrate(self, connection: Union[BaseDatabaseWrapper, str]) -> bool: ... @property def verbose_name_raw(self) -> str: ... @property diff --git a/django-stubs/test/testcases.pyi b/django-stubs/test/testcases.pyi index 67a565c..2a70b07 100644 --- a/django-stubs/test/testcases.pyi +++ b/django-stubs/test/testcases.pyi @@ -6,7 +6,7 @@ from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Ty from django.core.exceptions import ImproperlyConfigured from django.core.handlers.wsgi import WSGIHandler from django.core.servers.basehttp import ThreadedWSGIServer, WSGIRequestHandler -from django.db.backends.sqlite3.base import DatabaseWrapper +from django.db.backends.base.base import BaseDatabaseWrapper from django.db.models.base import Model from django.db.models.query import QuerySet, RawQuerySet from django.forms.fields import EmailField @@ -205,7 +205,7 @@ class LiveServerThread(threading.Thread): self, host: str, static_handler: Type[WSGIHandler], - connections_override: Dict[str, DatabaseWrapper] = ..., + connections_override: Dict[str, BaseDatabaseWrapper] = ..., port: int = ..., ) -> None: ... httpd: ThreadedWSGIServer = ...