Add type hints for the postgres CursorDebugWrapper and add missing method to the BaseCursorDebugWrapper (#585)

* Add type hints for the postgres CursorDebugWrapper, expand the BaseCursorDebugWrapper.

* Fix how Optinal gets applied.

* Fix optional handling further.

* Adjust postgres debugcursorwrapper to look more like the implementation.

* Apply review feedback.

Co-authored-by: LanDinh <coding+sourcetree@khaleesi.ninja>
This commit is contained in:
LanDinh
2021-04-18 12:50:25 +02:00
committed by GitHub
parent 4c90b5098f
commit 3931432b34
2 changed files with 18 additions and 8 deletions

View File

@@ -1,6 +1,8 @@
from typing import Dict, Tuple
from io import IOBase
from typing import Any, Dict, Optional, Tuple
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.utils import CursorDebugWrapper as BaseCursorDebugWrapper
def psycopg2_version() -> Tuple[int, ...]: ...
@@ -15,3 +17,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
_named_cursor_idx: int = ...
@property
def pg_version(self) -> str: ...
class CursorDebugWrapper(BaseCursorDebugWrapper):
def copy_expert(self, sql: str, file: IOBase, *args: Any): ...
def copy_to(self, file: IOBase, table: str, *args: Any, **kwargs: Any): ...

View File

@@ -1,13 +1,14 @@
import types
from datetime import date, datetime, time
from decimal import Decimal
from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Type, Union
from typing import Any, ContextManager, Dict, List, Mapping, Optional, Sequence, Tuple, Type, Union
from uuid import UUID
logger: Any
# Python types that can be adapted to SQL.
_SQLType = Union[None, bool, int, float, Decimal, str, bytes, datetime, UUID]
_ExecuteParameters = Optional[Union[Sequence[_SQLType], Mapping[str, _SQLType]]]
class CursorWrapper:
cursor: Any = ...
@@ -24,16 +25,19 @@ class CursorWrapper:
tb: Optional[types.TracebackType],
) -> None: ...
def callproc(self, procname: str, params: List[Any] = ..., kparams: Dict[str, int] = ...) -> Any: ...
def execute(
self, sql: str, params: Optional[Union[Sequence[_SQLType], Mapping[str, _SQLType]]] = ...
) -> Optional[Any]: ...
def executemany(
self, sql: str, param_list: Sequence[Optional[Union[Sequence[_SQLType], Mapping[str, _SQLType]]]]
) -> Optional[Any]: ...
def execute(self, sql: str, params: _ExecuteParameters = ...) -> Any: ...
def executemany(self, sql: str, param_list: Sequence[_ExecuteParameters]) -> Any: ...
class CursorDebugWrapper(CursorWrapper):
cursor: Any
db: Any
def debug_sql(
self,
sql: Optional[str] = ...,
params: Optional[Union[_ExecuteParameters, Sequence[_ExecuteParameters]]] = ...,
use_last_executed_query: bool = ...,
many: bool = ...,
) -> ContextManager[None]: ...
def typecast_date(s: Optional[str]) -> Optional[date]: ...
def typecast_time(s: Optional[str]) -> Optional[time]: ...