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

Static type checking with mypy doesn't work #6

Open
TheAfroOfDoom opened this issue Jul 18, 2022 · 0 comments
Open

Static type checking with mypy doesn't work #6

TheAfroOfDoom opened this issue Jul 18, 2022 · 0 comments
Labels
api Relating to the Django RF API enhancement New feature or request help wanted Extra attention is needed

Comments

@TheAfroOfDoom
Copy link
Owner

Went down a rabbit-hole with the following plugins trying to enable mypy so we can have static type checking on the backend API.

I think the combination of django-configurations and django-restframework are screwing up mypy's plugin system.

Ultimately I got blocked at this issue and found no way around it: typeddjango/django-stubs#461. So I'm dropping static typing via mypy for now.


I had the following configurations setup to get to the point of getting this error whenever I tried to import mypy_django_plugin.main:

backend/mypy.ini

[mypy]
plugins =
    ./configurations_mypy_django_plugin.py, mypy_drf_plugin.main

show_error_codes = True

[mypy.plugins.django-stubs]
django_settings_module = "api.config"

[mypy-api.*.migrations.*]
# Django migrations should not produce any errors:
ignore_errors = true

backend/configurations_mypy_django_plugin.py

# https://github.com/typeddjango/django-stubs/pull/180#issuecomment-820062352
# configurations_mypy_django_plugin.py
import os
from configurations.importer import install
from mypy.version import __version__

from mypy_django_plugin import main

# from mypy_drf_plugin import main


def plugin(version):
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.config")
    os.environ.setdefault("DJANGO_CONFIGURATION", "Local")
    install()
    return main.plugin(version)

Running py -3.9 -m mypy api --show-traceback gives this error message:

api\users\models.py:7: error: Skipping analyzing "django.dispatch": module is installed, but missing library stubs or py.typed marker  [import]
C:\Python39\lib\site-packages\rest_framework-stubs\authtoken\models.pyi:12: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.961
Traceback (most recent call last):
  File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "mypy\semanal.py", line 5350, in accept
  File "mypy\nodes.py", line 1028, in accept
  File "mypy\semanal.py", line 1123, in visit_class_def
  File "mypy\semanal.py", line 1203, in analyze_class
  File "mypy\semanal.py", line 1212, in analyze_class_body_common
  File "mypy\semanal.py", line 1257, in apply_class_plugin_hooks
  File "C:\Python39\lib\site-packages\mypy_django_plugin\main.py", line 48, in transform_model_class
    process_model_class(ctx, django_context)
  File "C:\Python39\lib\site-packages\mypy_django_plugin\transformers\models.py", line 514, in process_model_class
    initializer_cls(ctx, django_context).run()
  File "C:\Python39\lib\site-packages\mypy_django_plugin\transformers\models.py", line 70, in run
    self.run_with_model_cls(model_cls)
  File "C:\Python39\lib\site-packages\mypy_django_plugin\transformers\models.py", line 286, in run_with_model_cls
    assert (
AssertionError: Type info for Django's django.db.models.manager.Manager missing
C:\Python39\lib\site-packages\rest_framework-stubs\authtoken\models.pyi:12: : note: use --pdb to drop into pdb

I have not yet tried using the latest developer build as suggested by the error message (Please try using mypy master on GitHub: https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build).

@TheAfroOfDoom TheAfroOfDoom added enhancement New feature or request help wanted Extra attention is needed api Relating to the Django RF API labels Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Relating to the Django RF API enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant