Skip to content

Commit a7f74a1

Browse files
committed
Improve type for CursorWrapper.execute(params)
Not perfect. Based on simple cases from http://initd.org/psycopg/docs/usage.html#adaptation-of-python-values-to-sql-types
1 parent abde37a commit a7f74a1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

django-stubs/db/backends/utils.pyi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from datetime import date, datetime, time
22
from decimal import Decimal
3-
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union
3+
from typing import Any, Dict, Iterator, List, Mapping, Optional, Sequence, Tuple, Union
4+
from uuid import UUID
45

56
logger: Any
67

8+
# Python types that can be adapted to SQL.
9+
_SQLType = Union[None, bool, int, float, Decimal, str, bytes, datetime, UUID]
10+
711
class CursorWrapper:
812
cursor: Any = ...
913
db: Any = ...
@@ -15,10 +19,10 @@ class CursorWrapper:
1519
def __exit__(self, type: None, value: None, traceback: None) -> None: ...
1620
def callproc(self, procname: str, params: List[Any] = ..., kparams: Dict[str, int] = ...) -> Any: ...
1721
def execute(
18-
self, sql: str, params: Optional[Union[List[bool], List[datetime], List[float], Tuple]] = ...
22+
self, sql: str, params: Optional[Union[Sequence[_SQLType], Mapping[str, _SQLType]]] = ...
1923
) -> Optional[Any]: ...
2024
def executemany(
21-
self, sql: str, param_list: Union[Iterator[Any], List[Tuple[Union[int, str]]]]
25+
self, sql: str, param_list: Sequence[Optional[Union[Sequence[_SQLType], Mapping[str, _SQLType]]]]
2226
) -> Optional[Any]: ...
2327

2428
class CursorDebugWrapper(CursorWrapper):

0 commit comments

Comments
 (0)