|
2 | 2 | import logging |
3 | 3 |
|
4 | 4 | from sqlite3 import Cursor, Connection, ProgrammingError |
5 | | -from sqlite3.dbapi2 import _Parameters |
6 | 5 |
|
7 | 6 | from .fields import Field |
8 | | -from typing import Union, Any, Optional, Self |
| 7 | +from typing import Union, Any, Optional, Self, Protocol, TypeVar, Mapping |
9 | 8 |
|
10 | | -NULL = None # python None is same as "NULL" here |
| 9 | + |
| 10 | +NULL = None |
| 11 | +_T_co = TypeVar("_T_co", covariant=True) |
| 12 | + |
| 13 | + |
| 14 | +class SupportsLenAndGetItem(Protocol[_T_co]): |
| 15 | + def __len__(self) -> int: ... |
| 16 | + def __getitem__(self, __k: int) -> _T_co: ... |
| 17 | + |
| 18 | + |
| 19 | +_Parameters = type[ |
| 20 | + SupportsLenAndGetItem[str | int | float | Any | None]] | type[ |
| 21 | + Mapping[str, str | int | float | Any | None] |
| 22 | +] |
11 | 23 |
|
12 | 24 |
|
13 | 25 | class TableError(BaseException): |
@@ -218,15 +230,20 @@ def where(self, **kwargs: Any) -> Self: |
218 | 230 | ) |
219 | 231 | return self |
220 | 232 |
|
221 | | - def execute(self, __sql: str, __parameters: _Parameters = ...) -> Self: |
| 233 | + def execute( # type: ignore |
| 234 | + self, |
| 235 | + __sql: str, |
| 236 | + *__parameters: _Parameters |
| 237 | + ) -> Self: |
222 | 238 | self._query = __sql |
223 | 239 | if __parameters: |
224 | | - for param in __parameters: |
| 240 | + for param in __parameters: # type: ignore |
225 | 241 | self._query.replace("?", param, 1) # type: ignore |
226 | | - return super().execute(__sql, __parameters) |
| 242 | + return super().execute(__sql, __parameters) # type: ignore |
227 | 243 |
|
228 | 244 | def fetch( |
229 | | - self, one: bool = False |
| 245 | + self, |
| 246 | + one: bool = False |
230 | 247 | ) -> Optional[Union[tuple[Any], list[Any]] | Any]: |
231 | 248 | """ |
232 | 249 | fetch values from cursor query |
|
0 commit comments