Skip to content

Commit

Permalink
Improve types of ConnectionProxy (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos authored Jul 4, 2024
1 parent 085b91b commit 1a5494c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
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

0 comments on commit 1a5494c

Please sign in to comment.