ogr
ogr

Reputation: 690

django and mypy with apps in a subfolder

We have a Django project with the following setup:

We have our apps in an apps folder. We added all those apps to the python path at settings.py level.

We then can refer and import these apps like so:

from apps.booking.models import Booking
# or
from booking.models import Booking

Now, we want to use mypy for type checking purposes.

The issue is that mypy does not recognize the import from booking.models import Booking and complains about missing stubs for this module. This make the typing very unreliable and not very useful as Booking is then typed as Any. It works fine with an import as follow however from apps.booking.models import Booking

Is there a way to make mypy understand the path without the prefix apps. ?

I tried to use mypy_path = $MYPY_CONFIG_FILE_DIR/apps in mypy.ini but without any success...

Edit:

For clarity, here is my full mypy.ini:

[mypy]
mypy_path = $MYPY_CONFIG_FILE_DIR/apps
show_error_codes = true
sqlite_cache = true
plugins =
    mypy_django_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = "myapp.settings"

Upvotes: 2

Views: 1067

Answers (1)

Daxton Kamitaira
Daxton Kamitaira

Reputation: 23

I think, it's because of __init__.py file. Did you add __init__.py file in your apps folder?

Upvotes: 0

Related Questions