Skip to content
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

[mypy] Enforce Mypy checks for a subset of modules #208

Merged
merged 1 commit into from
Nov 22, 2022

Conversation

john-bodley
Copy link
Contributor

@john-bodley john-bodley commented Jul 27, 2022

Even though Mypy is enabled, per this pre-commit hook, the default options are fairly loose which allows for untyped methods and calls.

This PR aims to slowly start tightening the screws module by module (resulting in digestible PRs) —starting with trino.exceptions, trino.logging, and trino.transactions—by enforcing typed methods, calls, etc. which improves code clarity and correctness.

The hope is over time contributors can systematically go through module by module and ensure all methods are correctly typed and remove them from the ignore list.

@cla-bot cla-bot bot added the cla-signed label Jul 27, 2022
setup.cfg Show resolved Hide resolved
Comment on lines +22 to +23
[mypy-tests.*,trino.auth,trino.client,trino.dbapi,trino.sqlalchemy.*]
ignore_errors = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mypy errors are ignored it these packages? For instance I see that you addressed some in trino.client.py, is it leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hovaesco I added this comment which hopefully explains why the change in trino/client.py is required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is mypy-tests.* module? Some leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hashhar mypy-tests is not a module, see here for specifics, but per,

Additional sections named [mypy-PATTERN1,PATTERN2,...] may be present, where PATTERN1, PATTERN2, etc., are comma-separated patterns of fully-qualified module names, with some components optionally replaced by the ‘’ character (e.g. foo.bar, foo.bar., foo.*.baz). These sections specify additional flags that only apply to modules whose name matches at least one of the patterns.

the TL;DR is for the tests.*, trino.auth, etc. modules errors are currently being ignored.

@@ -456,7 +456,7 @@ def statement_url(self) -> str:
def next_uri(self) -> Optional[str]:
return self._next_uri

def post(self, sql, additional_http_headers=None):
def post(self, sql: str, additional_http_headers: Optional[Dict[str, Any]] = None):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of yet I'm unsure of the return type. This should become clearer when the module has type enforcement. This method (as well as get) are required to have their arguments typed given they're called in trino/transaction.py and we have disallow_untyped_calls = true set.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
Copy link
Contributor

@mdesmet mdesmet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add to the developers setup section in the README how to automatically execute the pre-commit hook when committing as in https://pre-commit.com/#usage

@mdesmet mdesmet requested review from hashhar and ebyhr August 11, 2022 18:26
@hashhar
Copy link
Member

hashhar commented Aug 18, 2022

@mdesmet @hovaesco I'm fine merging this % #208 (comment). Can you send a follow-up PR with updated instructions in the README.md?

@hashhar hashhar mentioned this pull request Aug 19, 2022
@mdesmet
Copy link
Contributor

mdesmet commented Oct 14, 2022

@hashhar : Let's merge this. I will add another PR with updated instructions.

@ebyhr
Copy link
Member

ebyhr commented Nov 2, 2022

@john-bodley Could you rebase on upstream to resolve conflicts?

@hashhar hashhar force-pushed the john-bodley--mypy-enforcement branch from 0b958a1 to 1972425 Compare November 22, 2022 10:26
@hashhar
Copy link
Member

hashhar commented Nov 22, 2022

@john-bodley I've rebased to resolve conflicts - no other changes. Once CI finishes and is green we'll merge this. Thanks for doing this work and sorry it took so long to get it done.

@hashhar hashhar merged commit 9d1512a into trinodb:master Nov 22, 2022
@hashhar hashhar added the no-release-notes This pull request does not require release notes entry label Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed no-release-notes This pull request does not require release notes entry
Development

Successfully merging this pull request may close these issues.

None yet

5 participants