Skip to content

Commit 1a5494c

Browse files
authored
Improve types of ConnectionProxy (#2246)
1 parent 085b91b commit 1a5494c

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

django-stubs/core/cache/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ class CacheHandler(BaseConnectionHandler[BaseCache]):
1717

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

20-
cache: BaseCache
2120
caches: CacheHandler
21+
# Actually ConnectionProxy, but quacks exactly like BaseCache, it's not worth distinguishing the two.
22+
cache: BaseCache

django-stubs/db/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from .utils import ProgrammingError as ProgrammingError
1616

1717
connections: ConnectionHandler
1818
router: ConnectionRouter
19-
# Actually DefaultConnectionProxy, but quacks exactly like BaseDatabaseWrapper, it's not worth distinguishing the two.
19+
# Actually ConnectionProxy, but quacks exactly like BaseDatabaseWrapper, it's not worth distinguishing the two.
2020
connection: BaseDatabaseWrapper
2121

2222
def close_old_connections(**kwargs: Any) -> None: ...

django-stubs/utils/connection.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
from collections.abc import Iterator, Mapping, Sequence
1+
from collections.abc import Iterator, Sequence
22
from typing import Any, Generic, TypeVar
33

44
from django.utils.functional import cached_property
55

6-
class ConnectionProxy:
7-
def __init__(self, connections: Mapping[str, Any], alias: str) -> None: ...
8-
def __getattr__(self, item: str) -> Any: ...
9-
def __setattr__(self, name: str, value: Any) -> None: ...
6+
_T = TypeVar("_T")
7+
8+
class ConnectionProxy(Generic[_T]):
9+
def __init__(self, connections: BaseConnectionHandler[_T], alias: str) -> None: ...
10+
def __getattr__(self, item: str) -> _T: ...
11+
def __setattr__(self, name: str, value: _T) -> None: ...
1012
def __delattr__(self, name: str) -> None: ...
1113
def __contains__(self, key: str) -> bool: ...
1214
def __eq__(self, other: object) -> bool: ...
1315

1416
class ConnectionDoesNotExist(Exception): ...
1517

16-
_T = TypeVar("_T")
17-
1818
class BaseConnectionHandler(Generic[_T]):
1919
settings_name: str | None
2020
exception_class: type[Exception]

0 commit comments

Comments
 (0)