mirror of
https://github.com/davidhalter/django-stubs.git
synced 2026-05-24 17:28:41 +08:00
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:
@@ -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.base.base import BaseDatabaseWrapper
|
||||||
|
from django.db.backends.utils import CursorDebugWrapper as BaseCursorDebugWrapper
|
||||||
|
|
||||||
def psycopg2_version() -> Tuple[int, ...]: ...
|
def psycopg2_version() -> Tuple[int, ...]: ...
|
||||||
|
|
||||||
@@ -15,3 +17,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
|||||||
_named_cursor_idx: int = ...
|
_named_cursor_idx: int = ...
|
||||||
@property
|
@property
|
||||||
def pg_version(self) -> str: ...
|
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): ...
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import types
|
import types
|
||||||
from datetime import date, datetime, time
|
from datetime import date, datetime, time
|
||||||
from decimal import Decimal
|
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
|
from uuid import UUID
|
||||||
|
|
||||||
logger: Any
|
logger: Any
|
||||||
|
|
||||||
# Python types that can be adapted to SQL.
|
# Python types that can be adapted to SQL.
|
||||||
_SQLType = Union[None, bool, int, float, Decimal, str, bytes, datetime, UUID]
|
_SQLType = Union[None, bool, int, float, Decimal, str, bytes, datetime, UUID]
|
||||||
|
_ExecuteParameters = Optional[Union[Sequence[_SQLType], Mapping[str, _SQLType]]]
|
||||||
|
|
||||||
class CursorWrapper:
|
class CursorWrapper:
|
||||||
cursor: Any = ...
|
cursor: Any = ...
|
||||||
@@ -24,16 +25,19 @@ class CursorWrapper:
|
|||||||
tb: Optional[types.TracebackType],
|
tb: Optional[types.TracebackType],
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
def callproc(self, procname: str, params: List[Any] = ..., kparams: Dict[str, int] = ...) -> Any: ...
|
def callproc(self, procname: str, params: List[Any] = ..., kparams: Dict[str, int] = ...) -> Any: ...
|
||||||
def execute(
|
def execute(self, sql: str, params: _ExecuteParameters = ...) -> Any: ...
|
||||||
self, sql: str, params: Optional[Union[Sequence[_SQLType], Mapping[str, _SQLType]]] = ...
|
def executemany(self, sql: str, param_list: Sequence[_ExecuteParameters]) -> Any: ...
|
||||||
) -> Optional[Any]: ...
|
|
||||||
def executemany(
|
|
||||||
self, sql: str, param_list: Sequence[Optional[Union[Sequence[_SQLType], Mapping[str, _SQLType]]]]
|
|
||||||
) -> Optional[Any]: ...
|
|
||||||
|
|
||||||
class CursorDebugWrapper(CursorWrapper):
|
class CursorDebugWrapper(CursorWrapper):
|
||||||
cursor: Any
|
cursor: Any
|
||||||
db: 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_date(s: Optional[str]) -> Optional[date]: ...
|
||||||
def typecast_time(s: Optional[str]) -> Optional[time]: ...
|
def typecast_time(s: Optional[str]) -> Optional[time]: ...
|
||||||
|
|||||||
Reference in New Issue
Block a user