From eb49e57598ef7792d3791e975ba3cf0349b13c18 Mon Sep 17 00:00:00 2001 From: SaJH Date: Mon, 6 May 2024 02:58:15 +0900 Subject: [PATCH 1/2] Fix Any value for django.db.backends.mysql.base.DatabaseWrapper --- django-stubs/db/backends/mysql/base.pyi | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/django-stubs/db/backends/mysql/base.pyi b/django-stubs/db/backends/mysql/base.pyi index b51618314..b0d5315d3 100644 --- a/django-stubs/db/backends/mysql/base.pyi +++ b/django-stubs/db/backends/mysql/base.pyi @@ -8,6 +8,7 @@ from .creation import DatabaseCreation from .features import DatabaseFeatures from .introspection import DatabaseIntrospection from .operations import DatabaseOperations +from .schema import DatabaseSchemaEditor from .validation import DatabaseValidation version: Any @@ -39,20 +40,20 @@ class DatabaseWrapper(BaseDatabaseWrapper): validation_class: type[DatabaseValidation] vendor: str - data_types: Any - operators: Any + data_types: dict[str, str] + operators: dict[str, str] pattern_esc: str - pattern_ops: Any - isolation_levels: Any + pattern_ops: dict[str, str] + isolation_levels: set[str] Database: Any - SchemaEditorClass: Any - isolation_level: Any + SchemaEditorClass: type[DatabaseSchemaEditor] + isolation_level: set[str] def get_connection_params(self) -> dict[str, Any]: ... def get_new_connection(self, conn_params: Any) -> Any: ... def init_connection_state(self) -> None: ... def create_cursor(self, name: Any | None = ...) -> CursorWrapper: ... def disable_constraint_checking(self) -> Literal[True]: ... - needs_rollback: Any + needs_rollback: bool def enable_constraint_checking(self) -> None: ... def check_constraints(self, table_names: Any | None = ...) -> None: ... def is_usable(self) -> bool: ... From 818b2b8789cf5eaffb12981e13eaa352f65e7862 Mon Sep 17 00:00:00 2001 From: SaJH Date: Sat, 11 May 2024 23:16:29 +0900 Subject: [PATCH 2/2] Improve typing of django.db.backends.mysql.base.DatabaseWrapper attributes --- django-stubs/db/backends/mysql/base.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/django-stubs/db/backends/mysql/base.pyi b/django-stubs/db/backends/mysql/base.pyi index b0d5315d3..cb9cb0a69 100644 --- a/django-stubs/db/backends/mysql/base.pyi +++ b/django-stubs/db/backends/mysql/base.pyi @@ -1,5 +1,5 @@ from collections.abc import Container, Iterator -from typing import Any, Literal +from typing import Any, Literal, Protocol from django.db.backends.base.base import BaseDatabaseWrapper @@ -15,6 +15,8 @@ version: Any django_conversions: Any server_version_re: Any +class MySQLDatabase(Protocol): ... + class CursorWrapper: codes_for_integrityerror: Any cursor: Any @@ -40,12 +42,11 @@ class DatabaseWrapper(BaseDatabaseWrapper): validation_class: type[DatabaseValidation] vendor: str - data_types: dict[str, str] operators: dict[str, str] pattern_esc: str pattern_ops: dict[str, str] isolation_levels: set[str] - Database: Any + Database: MySQLDatabase SchemaEditorClass: type[DatabaseSchemaEditor] isolation_level: set[str] def get_connection_params(self) -> dict[str, Any]: ... @@ -53,7 +54,6 @@ class DatabaseWrapper(BaseDatabaseWrapper): def init_connection_state(self) -> None: ... def create_cursor(self, name: Any | None = ...) -> CursorWrapper: ... def disable_constraint_checking(self) -> Literal[True]: ... - needs_rollback: bool def enable_constraint_checking(self) -> None: ... def check_constraints(self, table_names: Any | None = ...) -> None: ... def is_usable(self) -> bool: ...