Add type hints and enable mypy for client.py and dbapi.py#324
Add type hints and enable mypy for client.py and dbapi.py#324damian3031 wants to merge 5 commits intotrinodb:masterfrom
Conversation
|
|
||
| def genall(self): | ||
| return self._query.result | ||
| def genall(self) -> Any: |
There was a problem hiding this comment.
| def genall(self) -> Any: | |
| def genall(self) -> Optional[trino.client.TrinoResult]: |
There was a problem hiding this comment.
mypy throws error then:
trino/dbapi.py:615: error: Argument 1 to "list" has incompatible type "Optional[TrinoResult]"; expected "Iterable[List[Any]]" [arg-type]
changing to Iterable[List[Any]] throws error elsewhere, and so on
57c9706 to
f58375e
Compare
7998fb7 to
4b6e2e3
Compare
mdesmet
left a comment
There was a problem hiding this comment.
LGTM % the Iterator comment
| PROXIES = {} | ||
|
|
||
| _HEADER_EXTRA_CREDENTIAL_KEY_REGEX = re.compile(r'^\S[^\s=]*$') | ||
| _HEADER_EXTRA_CREDENTIAL_KEY_REGEX = re.compile(r"^\S[^\s=]*$") |
There was a problem hiding this comment.
separate out a commit, having functional and non-functional changes in single commit makes it harder to read history (bisecting for example) in future.
There was a problem hiding this comment.
Extracted to separate commit
trino/dbapi.py
Outdated
| def commit(self): | ||
| if self.transaction is None: | ||
| def commit(self) -> None: | ||
| if self._transaction is None: |
There was a problem hiding this comment.
Used transaction property, instead of directly _transaction attribute
trino/dbapi.py
Outdated
| ) | ||
|
|
||
| def cursor(self, legacy_primitive_types: bool = None): | ||
| def cursor(self, legacy_primitive_types: Optional[bool] = None) -> 'Cursor': |
There was a problem hiding this comment.
-> 'Cursor'? Why no qualify the name?
There was a problem hiding this comment.
here and other places where we use "strings" as return types
There was a problem hiding this comment.
Fixed to use Postponed Evaluation of Annotations when type hint contains names that have not been defined yet.
| for parameters in seq_of_params[:-1]: | ||
| self.execute(operation, parameters) | ||
| self.fetchall() | ||
| assert self._query is not None |
There was a problem hiding this comment.
potential bugfix, extract a commit
There was a problem hiding this comment.
extracted to separate commit
| if self._query: | ||
| return self._query.result | ||
| return None |
There was a problem hiding this comment.
potential bugfix, extract a commit
There was a problem hiding this comment.
extracted to separate commit
d906660 to
e4e8bce
Compare
96998ec to
edc9e9a
Compare
edc9e9a to
3de613f
Compare
|
@hashhar I've adjusted to all your comments, PTAL |
part of #292
Added type hints and enabled mypy checks for
client.py,dbapi.py