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 types of ConnectionProxy #2246

Merged
merged 1 commit into from
Jul 4, 2024
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
3 changes: 2 additions & 1 deletion django-stubs/core/cache/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class CacheHandler(BaseConnectionHandler[BaseCache]):

def close_caches(**kwargs: Any) -> None: ...

cache: BaseCache
caches: CacheHandler
# Actually ConnectionProxy, but quacks exactly like BaseCache, it's not worth distinguishing the two.
cache: BaseCache
2 changes: 1 addition & 1 deletion django-stubs/db/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from .utils import ProgrammingError as ProgrammingError

connections: ConnectionHandler
router: ConnectionRouter
# Actually DefaultConnectionProxy, but quacks exactly like BaseDatabaseWrapper, it's not worth distinguishing the two.
# Actually ConnectionProxy, but quacks exactly like BaseDatabaseWrapper, it's not worth distinguishing the two.
connection: BaseDatabaseWrapper

def close_old_connections(**kwargs: Any) -> None: ...
Expand Down
14 changes: 7 additions & 7 deletions django-stubs/utils/connection.pyi
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from collections.abc import Iterator, Mapping, Sequence
from collections.abc import Iterator, Sequence
from typing import Any, Generic, TypeVar

from django.utils.functional import cached_property

class ConnectionProxy:
def __init__(self, connections: Mapping[str, Any], alias: str) -> None: ...
def __getattr__(self, item: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
_T = TypeVar("_T")

class ConnectionProxy(Generic[_T]):
def __init__(self, connections: BaseConnectionHandler[_T], alias: str) -> None: ...
def __getattr__(self, item: str) -> _T: ...
def __setattr__(self, name: str, value: _T) -> None: ...
def __delattr__(self, name: str) -> None: ...
def __contains__(self, key: str) -> bool: ...
def __eq__(self, other: object) -> bool: ...

class ConnectionDoesNotExist(Exception): ...

_T = TypeVar("_T")

class BaseConnectionHandler(Generic[_T]):
settings_name: str | None
exception_class: type[Exception]
Expand Down
Loading