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

ci: check types with mypy #1226

Merged
merged 9 commits into from
Apr 23, 2021
Merged

ci: check types with mypy #1226

merged 9 commits into from
Apr 23, 2021

Conversation

muggenhor
Copy link
Contributor

This is intended to (partially) address the CI concerns expressed in #1219 and #1223 and will result in partial type checking of the type annotations by using mypy. Keep in mind though that mypy is performing best-effort static analysis in a dynamically typed language so it can only partially check for correctness.

Some other tool(s) will be needed to have more complete type checking at runtime. E.g. typeguard.

In order to get mypy running successfully this also makes a few (as little as possible) changes to the type annotations. The mypy setting to require annotations on everything is commented out because there's way too much functions lacking annotations right now.

@muggenhor muggenhor changed the title ci: check types with mypy on CI ci: check types with mypy Apr 23, 2021
@Byron
Copy link
Member

Byron commented Apr 23, 2021

Thanks a lot for taking this on! Your effort is much appreciated, and also much needed to get GitPython back on track.

It appears that thanks to never actually running the type checker, the previous commits to add types weren't validated and seemingly aren't working (or are only working with python 3.9).

I have no idea how much additional work it would be to get mypy to pass, but if it's a dead-end it would certainly be alright to give up on types altogether and revert the commits that added them.

It's all up to you.

@muggenhor
Copy link
Contributor Author

Combined with #1227 this should pass now.

Without the presence of 'test-requirements.txt' 'tox' is unusable.
Because there's too many to fix quickly.
This gives mypy all information that it needs to determine what the
return type of a function call is *iff* it knows the argument's type.

As a result it can now stop complaining about passing None to str.join()
in exc.py.
By telling it where it's imported from in one case and telling it to
ignore it in another.
This will result in _partial_ type checking of the type annotations by
using mypy. Keep in mind though that mypy is performing _static_
analysis in a _dynamic_ language so it can only partially check for
correctness.

Some other tool(s) will be needed to have more complete type checking at
runtime. E.g. [typeguard].

[typeguard]: https://pypi.org/project/typeguard/
@muggenhor
Copy link
Contributor Author

muggenhor commented Apr 23, 2021

Rebased (to force test-rerun) after #1227 got merged.

Unfortunately it looks like the 3.9 build failed due to what looks like an intermittent failure. And I cannot retrigger a build without (another) force push....

@Byron Byron merged commit 4119a57 into gitpython-developers:main Apr 23, 2021
@Byron
Copy link
Member

Byron commented Apr 23, 2021

Thanks a million!

@muggenhor muggenhor deleted the testing branch April 23, 2021 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants