Skip to content

Commit 7f00488

Browse files
authored
add mypy.ini pyproject.toml (#64)
* add mypy.ini pyproject.toml * fix contextmanager type
1 parent 3f2b6c5 commit 7f00488

10 files changed

Lines changed: 108 additions & 69 deletions

File tree

mypy.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[mypy]
2+
plugins = pydantic.mypy
3+
4+
ignore_missing_imports = True
5+
follow_imports = silent
6+
strict_optional = True
7+
warn_redundant_casts = True
8+
warn_unused_ignores = True
9+
disallow_any_generics = True
10+
check_untyped_defs = True
11+
no_implicit_reexport = True
12+
13+
disallow_untyped_defs = True
14+
15+
[pydantic-mypy]
16+
init_forbid_extra = True
17+
init_typed = True
18+
warn_required_dynamic_aliases = True
19+
warn_untyped_fields = True

pydataapi/dbapi.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"""
2626

2727
# https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types
28-
JDBC_TYPES: Dict[int, Type] = {
28+
JDBC_TYPES: Dict[int, Type[Any]] = {
2929
# 2003: list # ARRAY 2003
3030
-5: int, # BIGINT -5
3131
# BINARY -2
@@ -68,7 +68,7 @@
6868
}
6969

7070

71-
def get_description(column_metadata: List[Dict[str, Any]]) -> Tuple:
71+
def get_description(column_metadata: List[Dict[str, Any]]) -> Tuple[Any, ...]:
7272
return tuple(
7373
(
7474
meta['label'], # name
@@ -170,9 +170,9 @@ def __init__(self, data_api: DataAPI) -> None:
170170

171171
self.closed = False
172172

173-
self.description: Optional[List] = None
173+
self.description: Optional[List[Any]] = None
174174

175-
self._rows: List[List] = []
175+
self._rows: List[List[Any]] = []
176176
self._rowcount: int = -1
177177
self._lastrowid: Optional[int] = None
178178

@@ -195,7 +195,7 @@ def execute(
195195
self.description = get_description( # type: ignore
196196
getattr(result, '_column_metadata')
197197
)
198-
rows: List[List] = getattr(result, '_rows')
198+
rows: List[List[Any]] = getattr(result, '_rows')
199199
self._rows = rows
200200
self._rowcount = len(rows) or result.number_of_records_updated
201201
self._lastrowid = result.generated_fields_first # type: ignore
@@ -209,23 +209,23 @@ def executemany(
209209
self._rows = [result.generated_fields for result in results]
210210
self._rowcount = len(self._rows)
211211
self.description = []
212-
self._lastrowid = ( # type: ignore
212+
self._lastrowid = (
213213
results[-1].generated_fields_first if results else None # type: ignore
214214
)
215215
return self
216216

217-
def fetchone(self) -> Optional[List]:
217+
def fetchone(self) -> Optional[List[Any]]:
218218
try:
219219
return self._rows.pop(0)
220220
except IndexError:
221221
return None
222222

223-
def fetchmany(self, size: Optional[int] = None) -> List[List]:
223+
def fetchmany(self, size: Optional[int] = None) -> List[List[Any]]:
224224
size = size or self.arraysize
225225
result, self._rows = self._rows[:size], self._rows[size:]
226226
return result
227227

228-
def fetchall(self) -> List[List]:
228+
def fetchall(self) -> List[List[Any]]:
229229
rows = self._rows
230230
self._rows = []
231231
return rows
@@ -236,7 +236,7 @@ def setinputsizes(self, sizes: Any) -> None: # pragma: no cover
236236
def setoutputsizes(self, sizes: Any) -> None: # pragma: no cover
237237
pass
238238

239-
def __iter__(self) -> Iterator[List]:
239+
def __iter__(self) -> Iterator[List[Any]]:
240240
return iter(self._rows)
241241

242242

pydataapi/dialect/base.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
from typing import Any, Callable, List, Optional, Pattern, Type, TypeVar, Union
55

66
from botocore.exceptions import ClientError
7-
from pydataapi.dbapi import Connection
87
from sqlalchemy import cast
98
from sqlalchemy.engine.default import DefaultDialect
109
from sqlalchemy.sql import sqltypes
1110
from sqlalchemy.sql.type_api import TypeEngine
1211

12+
from pydataapi.dbapi import Connection
13+
1314

1415
class DataAPIDialect(DefaultDialect, ABC):
1516
driver: str = 'dataapi'
@@ -41,12 +42,12 @@ def dbapi(cls) -> Type[Connection]:
4142

4243
DatetimeProtocol = Union[datetime.date, datetime.datetime, datetime.time]
4344

44-
DATE_PATTERN: Pattern = re.compile(r'^\d{4}-[0-1]\d-[0-3]\d$')
45+
DATE_PATTERN: Pattern[str] = re.compile(r'^\d{4}-[0-1]\d-[0-3]\d$')
4546

46-
DATETIME_PATTERN: Pattern = re.compile(
47+
DATETIME_PATTERN: Pattern[str] = re.compile(
4748
r'^\d{4}-[0-1]\d-[0-3]\d [0-2]\d:[0-6]\d:[0-6]\d$'
4849
)
49-
DATETIME_MICROSECOND_PATTERN: Pattern = re.compile(
50+
DATETIME_MICROSECOND_PATTERN: Pattern[str] = re.compile(
5051
r'^\d{4}-[0-1]\d-[0-3]\d [0-2]\d:[0-6]\d:[0-6]\d\.\d{1,6}$'
5152
)
5253

@@ -75,15 +76,15 @@ class DataAPIDatetimeBase:
7576
def bind_expression(self, value: Any) -> Any:
7677
return cast(value, self.db_type)
7778

78-
def bind_processor(self, dialect: DataAPIDialect) -> Callable:
79+
def bind_processor(self, dialect: DataAPIDialect) -> Callable[..., Any]:
7980
def process_bind_value(value: Any) -> Any:
8081
if isinstance(value, self.python_type):
8182
return value.strftime(DATETIME_MICROSECOND_FORMAT)
8283
return value
8384

8485
return process_bind_value
8586

86-
def result_processor(self, dialect: DataAPIDialect, coltype: List) -> Any:
87+
def result_processor(self, dialect: DataAPIDialect, coltype: List[Any]) -> Any:
8788
def process_result_value(value: Any) -> Any:
8889
parsed_datetime = _parse_datetime(value)
8990
if parsed_datetime:

0 commit comments

Comments
 (0)