MyFinances icon indicating copy to clipboard operation
MyFinances copied to clipboard

MyPy Error Fix | Open to all

Open TreyWW opened this issue 1 year ago • 3 comments

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)

TreyWW avatar Apr 11 '24 14:04 TreyWW

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.

Domejko avatar Apr 11 '24 15:04 Domejko

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).

TreyWW avatar Apr 11 '24 15:04 TreyWW

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.

Domejko avatar Apr 11 '24 16:04 Domejko