GeeksCAT / nem-per-feina

Job portal application using Django
https://nemperfeina.cat
MIT License
20 stars 19 forks source link

Fix mypy issues #83

Open XaviTorello opened 3 years ago

XaviTorello commented 3 years ago

Is your feature request related to a problem? Please describe.

Current master code does not pass mypy validations

``` $ mypy --strict $(find . | grep '.py$' | grep -ve './*/migrations') manage.py:8: error: Skipping analyzing 'django.core.management': found module but no type hints or library stubs accounts/apps.py:1: error: Skipping analyzing 'django.apps': found module but no type hints or library stubs accounts/apps.py:4: error: Class cannot subclass 'AppConfig' (has type 'Any') accounts/managers.py:1: error: Skipping analyzing 'django.contrib.auth.models': found module but no type hints or library stubs accounts/managers.py:4: error: Class cannot subclass 'BaseUserManager' (has type 'Any') accounts/managers.py:9: error: Function is missing a type annotation accounts/managers.py:19: error: Function is missing a type annotation accounts/managers.py:23: error: Call to untyped function "_create_user" in typed context accounts/managers.py:25: error: Function is missing a type annotation accounts/managers.py:35: error: Call to untyped function "_create_user" in typed context accounts/admin.py:1: error: Skipping analyzing 'django.contrib': found module but no type hints or library stubs jobs/wsgi.py:12: error: Skipping analyzing 'whitenoise': found module but no type hints or library stubs jobs/wsgi.py:14: error: Skipping analyzing 'django.core.wsgi': found module but no type hints or library stubs jobs/urls.py:1: error: Skipping analyzing 'drf_yasg': found module but no type hints or library stubs jobs/urls.py:2: error: Skipping analyzing 'drf_yasg.views': found module but no type hints or library stubs jobs/urls.py:3: error: Skipping analyzing 'rest_framework': found module but no type hints or library stubs jobs/urls.py:5: error: Skipping analyzing 'django.contrib': found module but no type hints or library stubs jobs/urls.py:6: error: Skipping analyzing 'django.urls': found module but no type hints or library stubs tests/jobsapp/test_jopsapp.py:1: error: Cannot find implementation or library stub for module named 'pytest' tests/jobsapp/test_jopsapp.py:3: error: Cannot find implementation or library stub for module named 'tests.factories' tests/jobsapp/test_jopsapp.py:9: error: Function is missing a return type annotation tests/jobsapp/test_jopsapp.py:9: note: Use "-> None" if function does not return a value jobsapp/apps.py:1: error: Skipping analyzing 'django.apps': found module but no type hints or library stubs jobsapp/apps.py:4: error: Class cannot subclass 'AppConfig' (has type 'Any') jobsapp/api/custom_exception.py:1: error: Skipping analyzing 'rest_framework.exceptions': found module but no type hints or library stubs jobsapp/api/custom_exception.py:2: error: Skipping analyzing 'rest_framework.views': found module but no type hints or library stubs jobsapp/api/custom_exception.py:5: error: Function is missing a type annotation jobsapp/api/permissions.py:1: error: Skipping analyzing 'rest_framework.permissions': found module but no type hints or library stubs jobsapp/api/permissions.py:4: error: Class cannot subclass 'BasePermission' (has type 'Any') jobsapp/api/permissions.py:5: error: Function is missing a type annotation jobsapp/api/permissions.py:9: error: Class cannot subclass 'BasePermission' (has type 'Any') jobsapp/api/permissions.py:10: error: Function is missing a type annotation jobsapp/decorators.py:1: error: Skipping analyzing 'django.core.exceptions': found module but no type hints or library stubs jobsapp/decorators.py:4: error: Function is missing a type annotation jobsapp/decorators.py:5: error: Function is missing a type annotation jobsapp/decorators.py:15: error: Function is missing a type annotation jobsapp/decorators.py:16: error: Function is missing a type annotation jobsapp/admin.py:1: error: Skipping analyzing 'django.contrib': found module but no type hints or library stubs accounts/models.py:1: error: Skipping analyzing 'django.contrib.auth.models': found module but no type hints or library stubs accounts/models.py:2: error: Skipping analyzing 'django.db': found module but no type hints or library stubs accounts/models.py:9: error: Class cannot subclass 'AbstractUser' (has type 'Any') accounts/models.py:22: error: Need type annotation for 'REQUIRED_FIELDS' (hint: "REQUIRED_FIELDS: List[] = ...") accounts/models.py:24: error: Function is missing a return type annotation accounts/api/serializers.py:1: error: Skipping analyzing 'rest_framework': found module but no type hints or library stubs accounts/api/serializers.py:6: error: Class cannot subclass 'ModelSerializer' (has type 'Any') accounts/api/serializers.py:21: error: Class cannot subclass 'ModelSerializer' (has type 'Any') accounts/api/serializers.py:40: error: Function is missing a type annotation accounts/forms.py:1: error: Skipping analyzing 'django': found module but no type hints or library stubs accounts/forms.py:2: error: Skipping analyzing 'django.contrib.auth': found module but no type hints or library stubs accounts/forms.py:3: error: Skipping analyzing 'django.contrib.auth.forms': found module but no type hints or library stubs accounts/forms.py:10: error: Class cannot subclass 'UserCreationForm' (has type 'Any') accounts/forms.py:13: error: Function is missing a type annotation accounts/forms.py:71: error: Function is missing a return type annotation accounts/forms.py:77: error: Function is missing a type annotation accounts/forms.py:85: error: Class cannot subclass 'UserCreationForm' (has type 'Any') accounts/forms.py:86: error: Function is missing a type annotation accounts/forms.py:133: error: Function is missing a type annotation accounts/forms.py:141: error: Class cannot subclass 'Form' (has type 'Any') accounts/forms.py:149: error: Function is missing a type annotation accounts/forms.py:155: error: Function is missing a type annotation accounts/forms.py:171: error: Function is missing a return type annotation accounts/forms.py:175: error: Class cannot subclass 'ModelForm' (has type 'Any') accounts/forms.py:176: error: Function is missing a type annotation jobs/settings/__init__.py:4: error: Skipping analyzing 'environ': found module but no type hints or library stubs jobs/settings/__init__.py:76: error: Need type annotation for 'AUTH_PASSWORD_VALIDATORS' (hint: "AUTH_PASSWORD_VALIDATORS: List[] = ...") jobsapp/models.py:1: error: Skipping analyzing 'django.db': found module but no type hints or library stubs jobsapp/models.py:2: error: Skipping analyzing 'django.utils': found module but no type hints or library stubs jobsapp/models.py:7: error: Class cannot subclass 'Model' (has type 'Any') jobsapp/models.py:30: error: Function is missing a return type annotation jobsapp/models.py:34: error: Class cannot subclass 'Model' (has type 'Any') jobsapp/models.py:42: error: Function is missing a return type annotation accounts/api/custom_claims.py:1: error: Skipping analyzing 'rest_framework_simplejwt.serializers': found module but no type hints or library stubs accounts/api/custom_claims.py:2: error: Skipping analyzing 'rest_framework_simplejwt.views': found module but no type hints or library stubs accounts/api/custom_claims.py:7: error: Class cannot subclass 'TokenObtainPairSerializer' (has type 'Any') accounts/api/custom_claims.py:9: error: Function is missing a type annotation accounts/api/custom_claims.py:18: error: Class cannot subclass 'TokenObtainPairView' (has type 'Any') accounts/api/views.py:1: error: Skipping analyzing 'rest_framework': found module but no type hints or library stubs accounts/api/views.py:3: error: Skipping analyzing 'django.contrib.auth': found module but no type hints or library stubs accounts/api/views.py:12: error: Function is missing a type annotation accounts/views.py:1: error: Skipping analyzing 'django.contrib': found module but no type hints or library stubs accounts/views.py:2: error: Skipping analyzing 'django.http': found module but no type hints or library stubs accounts/views.py:3: error: Skipping analyzing 'django.shortcuts': found module but no type hints or library stubs accounts/views.py:4: error: Skipping analyzing 'django.views.generic': found module but no type hints or library stubs accounts/views.py:10: error: Class cannot subclass 'CreateView' (has type 'Any') accounts/views.py:18: error: Function is missing a type annotation accounts/views.py:23: error: Function is missing a type annotation accounts/views.py:25: error: Call to untyped function (unknown) in typed context accounts/views.py:28: error: Call to untyped function "save" in typed context accounts/views.py:37: error: Class cannot subclass 'CreateView' (has type 'Any') accounts/views.py:45: error: Function is missing a type annotation accounts/views.py:50: error: Function is missing a type annotation accounts/views.py:52: error: Call to untyped function (unknown) in typed context accounts/views.py:55: error: Call to untyped function "save" in typed context accounts/views.py:64: error: Class cannot subclass 'FormView' (has type 'Any') accounts/views.py:75: error: Function is missing a type annotation accounts/views.py:77: error: Call to untyped function "get_success_url" in typed context accounts/views.py:80: error: Function is missing a return type annotation accounts/views.py:86: error: Function is missing a return type annotation accounts/views.py:89: error: Function is missing a type annotation accounts/views.py:91: error: Call to untyped function "get_success_url" in typed context accounts/views.py:93: error: Function is missing a type annotation accounts/views.py:98: error: Class cannot subclass 'RedirectView' (has type 'Any') accounts/views.py:105: error: Function is missing a type annotation tests/factories.py:1: error: Cannot find implementation or library stub for module named 'factory' tests/factories.py:3: error: Module 'jobsapp.models' has no attribute 'User' tests/factories.py:7: error: Class cannot subclass 'DjangoModelFactory' (has type 'Any') tests/factories.py:16: error: Class cannot subclass 'DjangoModelFactory' (has type 'Any') tests/accounts/test_accounts.py:1: error: Cannot find implementation or library stub for module named 'pytest' tests/accounts/test_accounts.py:9: error: Function is missing a return type annotation tests/accounts/test_accounts.py:9: note: Use "-> None" if function does not return a value tests/accounts/test_accounts.py:10: error: Call to untyped function "EmployeeRegistrationForm" in typed context tests/accounts/test_accounts.py:11: error: Call to untyped function "save" in typed context jobsapp/api/serializers.py:1: error: Skipping analyzing 'rest_framework': found module but no type hints or library stubs jobsapp/api/serializers.py:8: error: Class cannot subclass 'ModelSerializer' (has type 'Any') jobsapp/api/serializers.py:16: error: Class cannot subclass 'ModelSerializer' (has type 'Any') jobsapp/templatetags/is_already_applied.py:1: error: Skipping analyzing 'django': found module but no type hints or library stubs jobsapp/templatetags/is_already_applied.py:9: error: Function is missing a type annotation jobsapp/views/employee.py:1: error: Skipping analyzing 'django.contrib.auth.decorators': found module but no type hints or library stubs jobsapp/views/employee.py:2: error: Skipping analyzing 'django.http': found module but no type hints or library stubs jobsapp/views/employee.py:3: error: Skipping analyzing 'django.urls': found module but no type hints or library stubs jobsapp/views/employee.py:4: error: Skipping analyzing 'django.utils.decorators': found module but no type hints or library stubs jobsapp/views/employee.py:5: error: Skipping analyzing 'django.views.generic': found module but no type hints or library stubs jobsapp/views/employee.py:12: error: Class cannot subclass 'UpdateView' (has type 'Any') jobsapp/views/employee.py:21: error: Function is missing a type annotation jobsapp/views/employee.py:24: error: Function is missing a type annotation jobsapp/views/employee.py:26: error: Call to untyped function "get_object" in typed context jobsapp/views/employee.py:32: error: Function is missing a type annotation jobsapp/forms.py:1: error: Skipping analyzing 'django': found module but no type hints or library stubs jobsapp/forms.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports jobsapp/forms.py:6: error: Class cannot subclass 'ModelForm' (has type 'Any') jobsapp/forms.py:19: error: Function is missing a return type annotation jobsapp/forms.py:27: error: Function is missing a type annotation jobsapp/forms.py:34: error: Class cannot subclass 'ModelForm' (has type 'Any') accounts/api/urls.py:1: error: Skipping analyzing 'rest_framework_simplejwt.views': found module but no type hints or library stubs accounts/api/urls.py:3: error: Skipping analyzing 'django.urls': found module but no type hints or library stubs accounts/urls.py:1: error: Skipping analyzing 'django.conf': found module but no type hints or library stubs accounts/urls.py:2: error: Skipping analyzing 'django.conf.urls.static': found module but no type hints or library stubs accounts/urls.py:3: error: Skipping analyzing 'django.urls': found module but no type hints or library stubs jobsapp/api/views/employee.py:1: error: Skipping analyzing 'rest_framework': found module but no type hints or library stubs jobsapp/api/views/employee.py:2: error: Skipping analyzing 'rest_framework.decorators': found module but no type hints or library stubs jobsapp/api/views/employee.py:3: error: Skipping analyzing 'rest_framework.generics': found module but no type hints or library stubs jobsapp/api/views/employee.py:4: error: Skipping analyzing 'rest_framework.permissions': found module but no type hints or library stubs jobsapp/api/views/employee.py:5: error: Skipping analyzing 'rest_framework.response': found module but no type hints or library stubs jobsapp/api/views/employee.py:12: error: Class cannot subclass 'CreateAPIView' (has type 'Any') jobsapp/api/views/employee.py:20: error: Function is missing a type annotation jobsapp/api/views/employee.py:28: error: Class cannot subclass 'ListAPIView' (has type 'Any') jobsapp/api/views/employee.py:32: error: Function is missing a return type annotation jobsapp/api/views/employee.py:41: error: Function is missing a type annotation jobsapp/api/views/employer.py:1: error: Skipping analyzing 'rest_framework.generics': found module but no type hints or library stubs jobsapp/api/views/employer.py:2: error: Skipping analyzing 'rest_framework.permissions': found module but no type hints or library stubs jobsapp/api/views/employer.py:9: error: Class cannot subclass 'ListAPIView' (has type 'Any') jobsapp/api/views/employer.py:13: error: Function is missing a return type annotation jobsapp/api/views/common.py:1: error: Skipping analyzing 'rest_framework': found module but no type hints or library stubs jobsapp/api/views/common.py:2: error: Skipping analyzing 'rest_framework.generics': found module but no type hints or library stubs jobsapp/api/views/common.py:3: error: Skipping analyzing 'rest_framework.permissions': found module but no type hints or library stubs jobsapp/api/views/common.py:8: error: Class cannot subclass 'ReadOnlyModelViewSet' (has type 'Any') jobsapp/api/views/common.py:14: error: Class cannot subclass 'ListAPIView' (has type 'Any') jobsapp/api/views/common.py:18: error: Function is missing a return type annotation jobsapp/views/employer.py:1: error: Skipping analyzing 'django.contrib.auth.decorators': found module but no type hints or library stubs jobsapp/views/employer.py:2: error: Skipping analyzing 'django.db': found module but no type hints or library stubs jobsapp/views/employer.py:3: error: Skipping analyzing 'django.http': found module but no type hints or library stubs jobsapp/views/employer.py:4: error: Skipping analyzing 'django.urls': found module but no type hints or library stubs jobsapp/views/employer.py:5: error: Skipping analyzing 'django.utils.decorators': found module but no type hints or library stubs jobsapp/views/employer.py:6: error: Skipping analyzing 'django.views.generic': found module but no type hints or library stubs jobsapp/views/employer.py:13: error: Class cannot subclass 'ListView' (has type 'Any') jobsapp/views/employer.py:20: error: Function is missing a type annotation jobsapp/views/employer.py:23: error: Function is missing a return type annotation jobsapp/views/employer.py:27: error: Class cannot subclass 'ListView' (has type 'Any') jobsapp/views/employer.py:35: error: Function is missing a type annotation jobsapp/views/employer.py:38: error: Function is missing a return type annotation jobsapp/views/employer.py:41: error: Function is missing a type annotation jobsapp/views/employer.py:47: error: Class cannot subclass 'CreateView' (has type 'Any') jobsapp/views/employer.py:54: error: Function is missing a type annotation jobsapp/views/employer.py:61: error: Function is missing a type annotation jobsapp/views/employer.py:65: error: Function is missing a type annotation jobsapp/views/employer.py:69: error: Call to untyped function "form_valid" in typed context jobsapp/views/employer.py:74: error: Class cannot subclass 'DeleteView' (has type 'Any') jobsapp/views/employer.py:80: error: Class cannot subclass 'ListView' (has type 'Any') jobsapp/views/employer.py:85: error: Function is missing a return type annotation jobsapp/views/employer.py:91: error: Function is missing a type annotation jobsapp/views/home.py:1: error: Skipping analyzing 'django.contrib': found module but no type hints or library stubs jobsapp/views/home.py:2: error: Skipping analyzing 'django.contrib.auth.decorators': found module but no type hints or library stubs jobsapp/views/home.py:3: error: Skipping analyzing 'django.http': found module but no type hints or library stubs jobsapp/views/home.py:4: error: Skipping analyzing 'django.urls': found module but no type hints or library stubs jobsapp/views/home.py:5: error: Skipping analyzing 'django.utils': found module but no type hints or library stubs jobsapp/views/home.py:6: error: Skipping analyzing 'django.utils.decorators': found module but no type hints or library stubs jobsapp/views/home.py:7: error: Skipping analyzing 'django.views.generic': found module but no type hints or library stubs jobsapp/views/home.py:14: error: Class cannot subclass 'ListView' (has type 'Any') jobsapp/views/home.py:19: error: Function is missing a return type annotation jobsapp/views/home.py:22: error: Function is missing a type annotation jobsapp/views/home.py:28: error: Class cannot subclass 'ListView' (has type 'Any') jobsapp/views/home.py:33: error: Function is missing a return type annotation jobsapp/views/home.py:43: error: Class cannot subclass 'ListView' (has type 'Any') jobsapp/views/home.py:50: error: Class cannot subclass 'DetailView' (has type 'Any') jobsapp/views/home.py:56: error: Function is missing a type annotation jobsapp/views/home.py:62: error: Function is missing a type annotation jobsapp/views/home.py:64: error: Call to untyped function "get_object" in typed context jobsapp/views/home.py:72: error: Class cannot subclass 'CreateView' (has type 'Any') jobsapp/views/home.py:79: error: Function is missing a type annotation jobsapp/views/home.py:82: error: Function is missing a type annotation jobsapp/views/home.py:86: error: Call to untyped function "form_valid" in typed context jobsapp/views/home.py:90: error: Function is missing a return type annotation jobsapp/views/home.py:99: error: Function is missing a type annotation jobsapp/views/home.py:106: error: Call to untyped function "get_success_url" in typed context jobsapp/api/urls.py:1: error: Skipping analyzing 'rest_framework.routers': found module but no type hints or library stubs jobsapp/api/urls.py:3: error: Skipping analyzing 'django.urls': found module but no type hints or library stubs jobsapp/urls.py:1: error: Skipping analyzing 'django.urls': found module but no type hints or library stubs Found 204 errors in 35 files (checked 46 source files) ```

Describe the solution you'd like

Those issues should be amended to ensure that base code is clean and ready to be improved :)

Describe alternatives you've considered

Temporaly relax this definition turning this MUST into an OPTIONAL, and just show pending issues as a warning into our code-check CI action Done in #84

Current proposal: As the test is now Optional, we can work with small PRs. Fix some files and link your PR to this issue. Ideal would be to split it per file, but some files have more errors than others, so I'm just listing them.

In order to avoid two PRs on the same file, please comment on this issue with the files you are fixing.

Files to fix:

Additional context Add any other context or screenshots about the feature request here.

ytturi commented 3 years ago

@XaviTorello @francescarpi What do you think about splitting this issue, so more people can grab a part of it? We can have one PR done as example on how to solve it for the people with less knowledge. And then they can pick up another part.

Maybe one per file?

XaviTorello commented 3 years ago

Perfect @ytturi :)

ytturi commented 3 years ago

I've updated the Issue description with an updated mypy run on origin/master. Also updated the proposal to fix it.

francescarpi commented 3 years ago

Perfect for me, as well. Thanks!

francescarpi commented 3 years ago

I've fixed: accounts/admin.py accounts/models.py accounts/managers.py

PR: #96

francescarpi commented 3 years ago

Example how to run mypy inside docker:

docker-compose run --rm test bash
mypy accounts/admin.py
francescarpi commented 3 years ago

Documentation: https://mypy.readthedocs.io/en/stable/