-
Notifications
You must be signed in to change notification settings - Fork 44
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
Enable mypy
and isort
in pre-commit & CI
#1346
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1346 +/- ##
==========================================
- Coverage 91.42% 91.33% -0.09%
==========================================
Files 72 72
Lines 4372 4363 -9
==========================================
- Hits 3997 3985 -12
- Misses 375 378 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
In principle, this is a good idea. |
b11f8c8
to
0992859
Compare
0992859
to
5ba3946
Compare
5ba3946
to
818d336
Compare
cbd91b0
to
49851eb
Compare
Sorry for the kinda monstrous PR @JPBergsma, I think I will split it into two PRs with isort and then mypy. I didn't have to change any tests from my mypy changes so hopefully it should all just work... |
For me, it is not necessary to split in two. I think both changes are quite orthogonal, so I can review both of them at the same time. |
Okay great, I guess my suggestion is to ignore the changes from 4782f5e and just check mypy first. The isort changes do not really need reviewing. Once you are happy with it I will rebase this PR into a few commits so that we have the separation going forward. |
(We can also merge your other PRs before this one!) |
I am still having some problems with PR#1304. The docker image setup seems to fail because of And the tests still fail for the elastic search backend. I tried to set up the docker container according to the installation instructions, but then I get an error that optimade can't connect to elastic search: "ERROR tests/server/middleware/test_api_hint.py - elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f4e5cdb62b0>: Failed to establish a new connection: [Errno 111] Connection ..." So I guess I still have some more work to do before my pr is merge ready. ps. after executing |
I also ran into this (#1377), not sure if the docker oneliner was tested before we upgrade to ES v7. Will try to address this in #1373 |
e0b97da
to
e41e81d
Compare
Just had to do a bit of a messy rebase after we merged that last PR, hope that doesn't mess up your review, but at least now the commits should each contain logical diffs |
When I run mypy on my machine, I still get two errors.
|
- Fix all implicit optional type hints (PEP484) - Replaces all `a: int = None` with `a: Optional[int] = None` - Automated with `pipx run no_implicit_optional <path>` - Add many mypy ignores - Fix importlib shenanigans
d821885
to
e92e1a5
Compare
e92e1a5
to
7ee9a97
Compare
7ee9a97
to
d8600f3
Compare
Thanks for the really thorough review @JPBergsma -- I think for the sake of our time, we can consider this PR ready... unless there's any objections I'll merge later today. |
If you want, you can merge it. I still have not finished reviewing all the files yet, so I may still suggest some changes in a later PR. |
Okay, happy to hold off if you want to keep going. |
I've just tried adding the |
I mostly try to understand why the ignore statement is needed. |
I have finished the review. So there should not be any new comments. |
Co-authored-by: Johan Bergsma <[email protected]>
01504c9
to
91acd47
Compare
Thanks @JPBergsma. I've addressed your final comments and will merge once the tests pass. |
mypy
and isort
in pre-commit & CI
message = msg.split("\n") | ||
if validator.verbosity > 1: | ||
# ValidationErrors from pydantic already include very detailed errors | ||
# that get duplicated in the traceback | ||
if not isinstance(result, ValidationError): | ||
message += traceback.split("\n") | ||
|
||
message = "\n".join(message) | ||
|
||
failure_type = 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.
I am not so happy with this line. The value of failure_type will be overwritten later on, so this assignment looks rather strange.
Is it such a problem to define the type on what is now line 377?
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.
Not a problem, but not of any importance, I don't think. I'd rather have the default value outside of the clause rather than a type-hint inside the clause. Not everything has to be explicitly typed (and we shouldn't let mypy dictate how we code beyond any real errors, especially as it changes between versions).
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
This PR fixes many broken/dodgy type hints in the code, and a few associated bugs/undefined behaviours.