Skip to content

Commit

Permalink
Improve database backend types (#1132)
Browse files Browse the repository at this point in the history
* Improve database backend types

* fixes
  • Loading branch information
adamchainz authored Aug 28, 2022
1 parent 11c5878 commit bfad3b0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
5 changes: 5 additions & 0 deletions django-stubs/db/backends/base/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ from django.db.backends.base.validation import BaseDatabaseValidation
from django.db.backends.utils import CursorDebugWrapper, CursorWrapper

NO_DB_ALIAS: str
RAN_DB_VERSION_CHECK: Set[str]

_T = TypeVar("_T", bound="BaseDatabaseWrapper")
_ExecuteWrapper = Callable[[Callable[[str, Any, bool, Dict[str, Any]], Any], str, Any, bool, Dict[str, Any]], Any]
Expand Down Expand Up @@ -64,6 +65,8 @@ class BaseDatabaseWrapper:
def queries_logged(self) -> bool: ...
@property
def queries(self) -> List[Dict[str, str]]: ...
def get_database_version(self) -> Tuple[int, ...]: ...
def check_database_version_supported(self) -> None: ...
def get_connection_params(self) -> Dict[str, Any]: ...
def get_new_connection(self, conn_params: Any) -> Any: ...
def init_connection_state(self) -> None: ...
Expand Down Expand Up @@ -105,6 +108,8 @@ class BaseDatabaseWrapper:
def make_cursor(self, cursor: CursorWrapper) -> CursorWrapper: ...
@contextmanager
def temporary_connection(self) -> Generator[CursorWrapper, None, None]: ...
@contextmanager
def _nodb_cursor(self) -> Generator[CursorWrapper, None, None]: ...
def schema_editor(self, *args: Any, **kwargs: Any) -> BaseDatabaseSchemaEditor: ...
def on_commit(self, func: Callable[[], None]) -> None: ...
def run_and_clear_commit_hooks(self) -> None: ...
Expand Down
20 changes: 12 additions & 8 deletions django-stubs/db/backends/base/features.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from typing import Any, Dict, Optional, Set, Type
from typing import Any, Dict, Optional, Sequence, Set, Tuple, Type

from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models.base import Model
from django.db.utils import DatabaseError

class BaseDatabaseFeatures:
minimum_database_version: Optional[Tuple[int, ...]]
gis_enabled: bool
allows_group_by_lob: bool
allows_group_by_pk: bool
allows_group_by_selected_pks: bool
empty_fetchmany_value: Any
empty_fetchmany_value: Sequence[Any]
update_can_self_select: bool
interprets_empty_strings_as_nulls: bool
supports_nullable_unique_constraints: bool
Expand Down Expand Up @@ -45,15 +47,14 @@ class BaseDatabaseFeatures:
nulls_order_largest: bool
supports_order_by_nulls_modifier: bool
order_by_nulls_first: bool
max_query_params: Any
max_query_params: Optional[int]
allows_auto_pk_0: bool
can_defer_constraint_checks: bool
supports_mixed_date_datetime_comparisons: bool
supports_tablespaces: bool
supports_sequence_reset: bool
can_introspect_default: bool
can_introspect_foreign_keys: bool
introspected_field_types: Any
introspected_field_types: Dict[str, str]
supports_index_column_ordering: bool
can_introspect_materialized_views: bool
can_distinct_on_fields: bool
Expand All @@ -63,14 +64,15 @@ class BaseDatabaseFeatures:
supports_combined_alters: bool
supports_foreign_keys: bool
can_create_inline_fk: bool
can_rename_index: bool
indexes_foreign_keys: bool
supports_column_check_constraints: bool
supports_table_check_constraints: bool
can_introspect_check_constraints: bool
supports_paramstyle_pyformat: bool
requires_literal_defaults: bool
connection_persists_old_columns: bool
closed_cursor_error_class: Any
closed_cursor_error_class: Type[DatabaseError]
has_case_insensitive_like: bool
bare_select_suffix: str
implied_column_null: bool
Expand All @@ -94,10 +96,11 @@ class BaseDatabaseFeatures:
create_test_procedure_without_params_sql: Optional[str]
create_test_procedure_with_int_param_sql: Optional[str]
supports_callproc_kwargs: bool
supported_explain_formats: Set[Any]
validates_explain_options: bool
supported_explain_formats: Set[str]
supports_default_in_lead_lag: bool
supports_ignore_conflicts: bool
supports_update_conflicts: bool
supports_update_conflicts_with_target: bool
requires_casted_case_in_updates: bool
supports_partial_indexes: bool
supports_functions_in_partial_indexes: bool
Expand All @@ -118,6 +121,7 @@ class BaseDatabaseFeatures:
supports_collation_on_textfield: bool
supports_non_deterministic_collations: bool
test_collations: Dict[str, Optional[str]]
test_now_utc_template: Optional[str]
django_test_expected_failures: Set[str]
django_test_skips: Dict[str, Set[str]]
connection: BaseDatabaseWrapper
Expand Down
14 changes: 7 additions & 7 deletions django-stubs/db/backends/mysql/base.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional, Type
from typing import Any, Container, Dict, Optional, Tuple, Type

from django.db.backends.base.base import BaseDatabaseWrapper as BaseDatabaseWrapper
from typing_extensions import Literal
Expand Down Expand Up @@ -57,16 +57,16 @@ class DatabaseWrapper(BaseDatabaseWrapper):
def check_constraints(self, table_names: Optional[Any] = ...) -> None: ...
def is_usable(self) -> bool: ...
@property
def display_name(self) -> str: ... # type: ignore
def display_name(self) -> str: ... # type: ignore [override]
@property
def data_type_check_constraints(self): ...
def data_type_check_constraints(self) -> Dict[str, str]: ... # type: ignore [override]
@property
def mysql_server_data(self) -> Dict[str, Any]: ...
@property
def mysql_server_info(self): ...
def mysql_server_info(self) -> str: ...
@property
def mysql_version(self): ...
def mysql_version(self) -> Tuple[int, ...]: ...
@property
def mysql_is_mariadb(self): ...
def mysql_is_mariadb(self) -> bool: ...
@property
def sql_mode(self): ...
def sql_mode(self) -> Container[str]: ...
2 changes: 1 addition & 1 deletion django-stubs/db/backends/mysql/features.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
@property
def can_introspect_foreign_keys(self) -> bool: ... # type: ignore
@property
def introspected_field_types(self) -> Dict[str, str]: ...
def introspected_field_types(self) -> Dict[str, str]: ... # type: ignore [override]
@property
def can_return_columns_from_insert(self) -> bool: ... # type: ignore
@property
Expand Down

0 comments on commit bfad3b0

Please sign in to comment.