Add mypy static code analysis to linting stack
Kind of request
Adding new functionality
Enhancement Description
I have run mypy over the code and there are some potential bugs in the code that should be fixed. The current count is around 500 issues, of which >90% can easily be fixed.
Use case
Mypy helps with type hints for static code analysis. It shows potential issues with missing None checks and type mismatches.
I find this example quite interesting:
# from model_api.py
if crs is None and hasattr(crs, "to_epsg"):
crs = crs.to_epsg() # not all CRS have an EPSG code
Mypy comes with:
"None" has no attribute "to_epsg"Mypyattr-defined
And I think that's fair. When you would put crs=None, hasattr will always return false. And the line below will actually never be called. And I can assume that there is no test for this case.
Additional Context
No response
very much in favour of this, though we'll need to find some time to dedicate to this. It will probably happen after v1 since in v1 we'll remove the mixins which should make it substantially easier.
Enabling mypy and fixing the errors for selected sub modules has been proposed as a requirement for our V1 release. The currently suggested modules are:
- [ ] Model
- [ ] Components
- [ ] Drivers
Anyone wants to either add or remove modules from this list?
I found this interesting post. https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options. Maybe it's good to set ourselves a limit to what we will fix and see if we can get 0 errors in that topic.