TreyWW / MyFinances

MyFinances is a web application that can help you as an individual, or team, manage your finances!
https://docs.myfinances.cloud
GNU Affero General Public License v3.0
97 stars 141 forks source link

MyPy Error Fix | Open to all #319

Closed TreyWW closed 4 months ago

TreyWW commented 5 months ago

As from #294 I'd like to slowly start decreasing the amount of MyPy errors throughout the project.

Any PRs are welcome to slowly remove, even just one mypy error at a time. Make sure in the PR not to add "closes 319" but just to add "Related issue".

Open to all, thanks @introkun for the idea and @Domejko for making a start.

Current (11/04/2024):

$ mypy .
backend\api\admin\api_keys.py:1: error: Skipping analyzing "django.contrib": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\admin\api_keys.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
backend\api\admin\api_keys.py:2: error: Skipping analyzing "django.http": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\admin\api_keys.py:3: error: Skipping analyzing "django.shortcuts": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\admin\urls.py:1: error: Skipping analyzing "django.urls": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\base\modal.py:3: error: Skipping analyzing "django.contrib": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\base\modal.py:4: error: Skipping analyzing "django.http": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\base\modal.py:6: error: Skipping analyzing "django.shortcuts": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\base\notifications.py:1: error: Skipping analyzing "django.http": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\base\notifications.py:2: error: Skipping analyzing "django.shortcuts": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\base\urls.py:1: error: Skipping analyzing "django.urls": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\clients\fetch.py:1: error: Skipping analyzing "django.db.models": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\clients\fetch.py:2: error: Skipping analyzing "django.http": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\clients\fetch.py:3: error: Skipping analyzing "django.shortcuts": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\clients\fetch.py:4: error: Skipping analyzing "django.views.decorators.http": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\clients\urls.py:1: error: Skipping analyzing "django.urls": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\currency_converter\convert.py:3: error: Skipping analyzing "django.contrib": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\currency_converter\convert.py:4: error: Skipping analyzing "django.http": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\currency_converter\convert.py:5: error: Skipping analyzing "django.shortcuts": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\currency_converter\convert.py:6: error: Skipping analyzing "forex_python.converter": module is installed, but missing library stubs or py.typed marker  [import-untyped]        
backend\api\currency_converter\urls.py:1: error: Skipping analyzing "django.urls": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\fetch.py:1: error: Skipping analyzing "django.contrib": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\fetch.py:2: error: Skipping analyzing "django.core.paginator": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\fetch.py:3: error: Skipping analyzing "django.db.models": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\fetch.py:4: error: Skipping analyzing "django.http": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\fetch.py:5: error: Skipping analyzing "django.shortcuts": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\fetch.py:6: error: Skipping analyzing "django_ratelimit.core": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\fetch.py:7: error: Skipping analyzing "django_ratelimit.decorators": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\send.py:9: error: Skipping analyzing "django.contrib": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\send.py:10: error: Skipping analyzing "django.core.exceptions": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\send.py:11: error: Skipping analyzing "django.core.handlers.wsgi": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\send.py:12: error: Skipping analyzing "django.core.validators": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\send.py:13: error: Skipping analyzing "django.db.models": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\send.py:14: error: Skipping analyzing "django.http": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\send.py:15: error: Skipping analyzing "django.shortcuts": module is installed, but missing library stubs or py.typed marker  [import-untyped]
backend\api\emails\send.py:16: error: Skipping analyzing "django.views.decorators.http": module is installed, but missing library stubs or py.typed marker  [import-untyped]
settings\helpers.py: error: Source file found twice under different module names: "helpers" and "settings.helpers"
settings\helpers.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
settings\helpers.py: note: Common resolutions include: a) adding `__init__.py` somewhere, b) using `--explicit-package-bases` or adjusting MYPYPATH
Found 36 errors in 12 files (errors prevented further checking)
Domejko commented 5 months ago

To see all the type errors we need to run mypy backend/ and mypy settings/ command. All those import errors from above except one are resolved with PR #318.

I'm not sure does all of those errors are real type errors because mypy has it's flaws but many of them can be resolved.

This article might be helpful for those who will want to work on the issue.

TreyWW commented 5 months ago

I think mypy ./ would be more ideal since that's every python file, not just the ones in backend/ or settings/ (and it does them all in one command).

Domejko commented 5 months ago

True, I did read now mypy documentation and due to the fact that settings/ got no __init__.py we need to pass a additional flag --explicit-package-bases. Without this flag he stops at

settings/helpers.py: error: Source file found twice under different module names: "helpers" and "settings.helpers"

because he don't know how to treat that file and checking is terminated.

So the command needs to be mypy --explicit-package-bases . and at the moment it finds 384 errors to tackle.