Skip to content

Commit 9d1512a

Browse files
john-bodleyhashhar
authored andcommitted
Enforce MyPy checks for a subset of modules
1 parent eef6388 commit 9d1512a

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ repos:
1111
- id: "mypy"
1212
name: "Python: types"
1313
additional_dependencies:
14-
- "types-pytz"
15-
- "types-requests"
14+
- "types-all"
1615

1716
- repo: https://github.com/pycqa/isort
1817
rev: 5.6.4

setup.cfg

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ test=pytest
44
[flake8]
55
max-line-length = 120
66
# W503 raises a warning when there is a line break before a binary operator.
7-
# This is best practice according to PEP 8 and the rule should be ignored.
7+
# This is best practice according to PEP 8 and the rule should be ignored.
88
#
99
# https://www.flake8rules.com/rules/W503.html
1010
# https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
1111
ignore = W503
12+
13+
[mypy]
14+
check_untyped_defs = true
15+
disallow_any_generics = true
16+
disallow_untyped_calls = true
17+
disallow_untyped_defs = true
18+
ignore_missing_imports = true
19+
no_implicit_optional = true
20+
warn_unused_ignores = true
21+
22+
[mypy-tests.*,trino.auth,trino.client,trino.dbapi,trino.sqlalchemy.*]
23+
ignore_errors = true

trino/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def statement_url(self) -> str:
492492
def next_uri(self) -> Optional[str]:
493493
return self._next_uri
494494

495-
def post(self, sql, additional_http_headers=None):
495+
def post(self, sql: str, additional_http_headers: Optional[Dict[str, Any]] = None):
496496
data = sql.encode("utf-8")
497497
# Deep copy of the http_headers dict since they may be modified for this
498498
# request by the provided additional_http_headers
@@ -524,7 +524,7 @@ def post(self, sql, additional_http_headers=None):
524524
)
525525
return http_response
526526

527-
def get(self, url):
527+
def get(self, url: str):
528528
return self._get(
529529
url,
530530
headers=self.http_headers,

trino/exceptions.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
This module defines exceptions for Trino operations. It follows the structure
1515
defined in pep-0249.
1616
"""
17-
17+
from typing import Any, Dict, Optional, Tuple
1818

1919
import trino.logging
2020

@@ -72,44 +72,44 @@ class TrinoDataError(NotSupportedError):
7272

7373

7474
class TrinoQueryError(Error):
75-
def __init__(self, error, query_id=None):
75+
def __init__(self, error: Dict[str, Any], query_id: Optional[str] = None) -> None:
7676
self._error = error
7777
self._query_id = query_id
7878

7979
@property
80-
def error_code(self):
80+
def error_code(self) -> Optional[int]:
8181
return self._error.get("errorCode", None)
8282

8383
@property
84-
def error_name(self):
84+
def error_name(self) -> Optional[str]:
8585
return self._error.get("errorName", None)
8686

8787
@property
88-
def error_type(self):
88+
def error_type(self) -> Optional[str]:
8989
return self._error.get("errorType", None)
9090

9191
@property
92-
def error_exception(self):
92+
def error_exception(self) -> Optional[str]:
9393
return self.failure_info.get("type", None) if self.failure_info else None
9494

9595
@property
96-
def failure_info(self):
96+
def failure_info(self) -> Optional[Dict[str, Any]]:
9797
return self._error.get("failureInfo", None)
9898

9999
@property
100-
def message(self):
100+
def message(self) -> str:
101101
return self._error.get("message", "Trino did not return an error message")
102102

103103
@property
104-
def error_location(self):
104+
def error_location(self) -> Tuple[int, int]:
105105
location = self._error["errorLocation"]
106106
return (location["lineNumber"], location["columnNumber"])
107107

108108
@property
109-
def query_id(self):
109+
def query_id(self) -> Optional[str]:
110110
return self._query_id
111111

112-
def __repr__(self):
112+
def __repr__(self) -> str:
113113
return '{}(type={}, name={}, message="{}", query_id={})'.format(
114114
self.__class__.__name__,
115115
self.error_type,
@@ -118,7 +118,7 @@ def __repr__(self):
118118
self.query_id,
119119
)
120120

121-
def __str__(self):
121+
def __str__(self) -> str:
122122
return repr(self)
123123

124124

trino/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
# TODO: provide interface to use ``logging.dictConfig``
19-
def get_logger(name, log_level=LEVEL):
19+
def get_logger(name: str, log_level: int = LEVEL) -> logging.Logger:
2020
logger = logging.getLogger(name)
2121
logger.setLevel(log_level)
2222
return logger

trino/transaction.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ def check(cls, level: int) -> int:
5050

5151

5252
class Transaction(object):
53-
def __init__(self, request):
53+
def __init__(self, request: trino.client.TrinoRequest) -> None:
5454
self._request = request
5555
self._id = NO_TRANSACTION
5656

5757
@property
58-
def id(self):
58+
def id(self) -> str:
5959
return self._id
6060

6161
@property
62-
def request(self):
62+
def request(self) -> trino.client.TrinoRequest:
6363
return self._request
6464

65-
def begin(self):
65+
def begin(self) -> None:
6666
response = self._request.post(START_TRANSACTION)
6767
if not response.ok:
6868
raise trino.exceptions.DatabaseError(
@@ -81,7 +81,7 @@ def begin(self):
8181
self._request.transaction_id = self._id
8282
logger.info("transaction started: %s", self._id)
8383

84-
def commit(self):
84+
def commit(self) -> None:
8585
query = trino.client.TrinoQuery(self._request, COMMIT)
8686
try:
8787
list(query.execute())
@@ -92,7 +92,7 @@ def commit(self):
9292
self._id = NO_TRANSACTION
9393
self._request.transaction_id = self._id
9494

95-
def rollback(self):
95+
def rollback(self) -> None:
9696
query = trino.client.TrinoQuery(self._request, ROLLBACK)
9797
try:
9898
list(query.execute())

0 commit comments

Comments
 (0)