Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve typing of django.db.backends.mysql.base.DatabaseWrapper attributes #2125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions django-stubs/db/backends/mysql/base.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -8,12 +8,15 @@ 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
django_conversions: Any
server_version_re: Any

class MySQLDatabase(Protocol): ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This protocol should have at least some attributes / methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having a hard time figuring it out. I think I just need to add methods or attributes related to the connection, but is there anything else I can include?


class CursorWrapper:
codes_for_integrityerror: Any
cursor: Any
Expand All @@ -39,20 +42,18 @@ class DatabaseWrapper(BaseDatabaseWrapper):
validation_class: type[DatabaseValidation]

vendor: str
data_types: Any
operators: Any
operators: dict[str, str]
pattern_esc: str
pattern_ops: Any
isolation_levels: Any
Database: Any
SchemaEditorClass: Any
isolation_level: Any
pattern_ops: dict[str, str]
isolation_levels: set[str]
Database: MySQLDatabase
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
def enable_constraint_checking(self) -> None: ...
def check_constraints(self, table_names: Any | None = ...) -> None: ...
def is_usable(self) -> bool: ...
Expand Down
Loading