-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type hints and enable mypy for client.py and dbapi.py #324
base: master
Are you sure you want to change the base?
Conversation
@@ -584,66 +603,22 @@ def describe(self, sql: str) -> List[DescribeOutput]: | |||
|
|||
return list(map(lambda x: DescribeOutput.from_row(x), result)) | |||
|
|||
def genall(self): | |||
return self._query.result | |||
def genall(self) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def genall(self) -> Any: | |
def genall(self) -> Optional[trino.client.TrinoResult]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % the Iterator comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first quick pass
@@ -75,7 +87,7 @@ | |||
else: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why go directly to field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used transaction
property, instead of directly _transaction
attribute
trino/dbapi.py
Outdated
@@ -207,7 +212,7 @@ def _create_request(self): | |||
self.request_timeout, | |||
) | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> 'Cursor'
? Why no qualify the name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here and other places where we use "strings" as return types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to use Postponed Evaluation of Annotations when type hint contains names that have not been defined yet.
@@ -503,6 +521,7 @@ def executemany(self, operation, seq_of_params): | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potential bugfix, extract a commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted to separate commit
if self._query: | ||
return self._query.result | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potential bugfix, extract a commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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