Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions django-stubs/db/backends/base/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from django.db.backends.base.introspection import BaseDatabaseIntrospection
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.backends.base.validation import BaseDatabaseValidation
from django.db.backends.utils import CursorDebugWrapper, CursorWrapper
from django.db.transaction import Atomic

NO_DB_ALIAS: str

Expand All @@ -33,11 +34,15 @@ class BaseDatabaseWrapper:
force_debug_cursor: bool = ...
autocommit: bool = ...
in_atomic_block: bool = ...
atomic_blocks: list[Atomic] = ...
savepoint_state: int = ...
savepoint_ids: Any = ...
commit_on_exit: bool = ...
needs_rollback: bool = ...
rollback_exc: Exception | None = ...
close_at: Any | None = ...
health_check_enabled: bool = ...
health_check_done: bool = ...
closed_in_transaction: bool = ...
errors_occurred: bool = ...
allow_thread_sharing: bool = ...
Expand All @@ -63,6 +68,8 @@ class BaseDatabaseWrapper:
@property
def queries(self) -> list[dict[str, str]]: ...
def get_connection_params(self) -> None: ...
def get_database_version(self) -> tuple[int, ...]: ...
def check_database_version_supported(self) -> None: ...
def get_new_connection(self, conn_params: Any) -> None: ...
def init_connection_state(self) -> None: ...
def create_cursor(self, name: Any | None = ...) -> None: ...
Expand Down Expand Up @@ -92,7 +99,10 @@ class BaseDatabaseWrapper:
def enable_constraint_checking(self) -> None: ...
def check_constraints(self, table_names: Any | None = ...) -> None: ...
def is_usable(self) -> None: ...
def close_if_health_check_failed(self) -> None: ...
def close_if_unusable_or_obsolete(self) -> None: ...
def inc_thread_sharing(self) -> None: ...
def dec_thread_sharing(self) -> None: ...
def validate_thread_sharing(self) -> None: ...
def prepare_database(self) -> None: ...
def wrap_database_errors(self) -> Any: ...
Expand Down
26 changes: 26 additions & 0 deletions tests/pyright/test_database_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .base import Result, run_pyright


def test_base_database_wrapper_declares_its_public_members() -> None:
"""Every public attribute and method BaseDatabaseWrapper defines is visible to the checker."""
results = run_pyright(
"""\
from django.db import connection

connection.inc_thread_sharing()
connection.dec_thread_sharing()
connection.check_database_version_supported()
connection.close_if_health_check_failed()
connection.get_database_version()
reveal_type(connection.atomic_blocks)
reveal_type(connection.health_check_done)
reveal_type(connection.health_check_enabled)
reveal_type(connection.rollback_exc)
"""
)
assert results == [
Result(type="information", message='Type of "connection.atomic_blocks" is "list[Atomic]"', line=8, column=13),
Result(type="information", message='Type of "connection.health_check_done" is "bool"', line=9, column=13),
Result(type="information", message='Type of "connection.health_check_enabled" is "bool"', line=10, column=13),
Result(type="information", message='Type of "connection.rollback_exc" is "Exception | None"', line=11, column=13),
]
Loading