-
Notifications
You must be signed in to change notification settings - Fork 78
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
test: add type hints and mypy
linting
#239
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Hi @faissaloux and thanks a lot for your contribution. I like type hints too. They make Python feel a little less interpreted and a little more statically typed. I will definitely take a look at this PR once I am done with adding the Cloud Monitoring MQL backend. Some commits I made there will make our life easier when it comes to linting and testing. |
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.
Thanks a lot for these annotations and the new MyPy target in the Makefile. I added a couple of suggestions for improvement.
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.
A lot of comments but not so many changes to make at the end of they day :-)
@lvaylet heeey sorry for late response π
I've got busy |
d611a54
to
2b3aa87
Compare
a99f30d
to
4a8452c
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.
Looking much better now! Just a few more changes and we should be good to go.
Also check the output of the CI for a handful of changes to make on Optional[str]
arguments: https://github.com/google/slo-generator/actions/runs/3259133646
Finally, no need to apologize for being busy. This is an open source project and I am really happy you take some personal time to work on it. No pressure.
About the What do you think! |
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.
Thanks a lot. I like how this looks.
You are right about bringing back Optional
for the checks. Just add from typing import Optional
at the top of the file, then a few Optional[str]
type hints when it makes sense, as you did for Dict
, Tuple
, List
...
12962d4
to
452152f
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.
Just a couple small changes left.
Also, please stick to the original code as much as possible. I do not fully understand the purpose of the new code you introduced in main.py
or other files (though I am sure there is a purpose :-)). Let's focus on type hints in this PR.
Oow yeah you right I wanted to but I found my self changing it because lint keeps failing so I have to fix it π About Now we still have some errors because of some duplicated code π |
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.
Looks good overall, thank you so much for taking the time to do this ! It will improve the dev experience and possibly ease-up some testing as well.
Some changes required, after that LGTM :)
128598b
to
b3c6357
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.
Thanks Faissal. Just restore the original code for self.client
in cloud_monitoring_mql.py
and we should be good to go.
Regarding the linting checks that fail, you can add # pylint: disable=duplicate-code
comments just above the definitions of good_bad_ratio()
and distribution_cut()
in cloud_monitoring.py
. Then you can check that everything works from your local machine by running make lint
. No need to wait for the CI pipeline to trigger.
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.
Good job. Now we need to work on making the pytype
tests pass. Proceed incrementally, starting with the error in api/main.py
mentioned below in a comment. Then make sure to run make lint
on your local machine before pushing. Ideally this is the last review. I wll proceed with merging this PR if all checks succeed.
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, thanks a lot @faissaloux!
* add type hints * add more type hints * fix lint * cleanup * integrate mypy test to tests workflow * fix types test workflow * disable more pylint options * add new line to mypy.ini * disable warnings locally * change Pylint annotation position * update .pylintrc * fix misc errors * feat: add pytype linting (#249) * add pytype linting and fix all reported errors * revert metaclass fix to make tests pass * refactor Makefile * fix mypy errors * more specific types in prometheus.py * remove Optional type on arguments with default * update test workflow * fix lint * fix unsubscriptable-object errors * refactor variables declarations and some typings * add new line on .gitignore file * remove clean from mypy make cmd * keep line before cmd * bring back Optional type * bring back Optional type on utils.py * reverse last commit * add Optional type to args in utils.py * wrong arg type * fix annotation-type-mismatch in compute.py * fix attribute-error on main.py * fix line too long * fix indentation * fix return types * add Optional type * fix already defined variables * fix None has no attribute * fix line too long * update Makefile mypy script * reverse last changes * reverse cloud_monitoring_mql init refactoring * ignore lint duplicate code warnings * skip pytype attribute-error error to fix later * ignore attr-defined type errors * ignore union-attr type errors * ignore fixme pylint warning * add missing types dependencies Co-authored-by: Laurent Vaylet <[email protected]>
Hello ππ»
On this PR I have added type hints β¨
resolves #232