14

When I am checking my modules through mypy it gives me this error:

Module 'django.contrib.gis' has no attribute 'forms'

and I am importing forms like this:

from django.contrib.gis import forms

I know it is correct but mypy shows this error message.

I could import like this: from django.contrib import gis and use forms as gis.forms but I do not want to.

Can anyone help me to fix this? Thanks.

evantkchong
  • 2,251
  • 3
  • 14
  • 29
Liya
  • 141
  • 1
  • 1
  • 4
  • it depends on where it going to importing django. like from system or virtual enviornment – Devang Hingu Mar 18 '20 at 06:05
  • my advise is to create one `virtualenvironment` and install django in it after activation of environment and run you project from that envornment. – Devang Hingu Mar 18 '20 at 06:07
  • I am doing all actions on docker – Liya Mar 18 '20 at 06:12
  • I know that using `from django.contrib import gis` is something you'd like to avoid but does that work? Also what version of mypy are you using? Your issue seems to be related to version 0.700 https://github.com/python/mypy/issues/7182 – evantkchong Mar 18 '20 at 07:04
  • @MoltenMuffins thank you. I will try to change version of mypy. Now I have mypy==0.761 – Liya Mar 18 '20 at 09:10
  • @Liya I don't mean you should downgrade, I was simply wondering if you were using 0.700 which had this issue. In any case, could you try running mypy with this flag `--implicit-reexport` and see if this resolves the issue? – evantkchong Mar 18 '20 at 09:12
  • @MoltenMuffins now mypy showing me another +500 errors, but that error with import disappeared. Anyway, thank you – Liya Mar 18 '20 at 10:24
  • @Liya Alright, I've made the comment an answer. If using the `--implicit-reexport` flag really was the solution to your issue, please accept my answer so others with the same issue would be able to know that this worked for you. However I have a feeling that it probably isn't the root cause of the problems you're facing. Is there anything in common for the +500 errors you're getting now? – evantkchong Mar 18 '20 at 17:00
  • This still doesn't work for version 0.990 – Tlaloc-ES Feb 15 '23 at 11:14

1 Answers1

14

It appears that your problem is similar to this issue raised in mypy's github repo:

Module X has no attribute Y, since version 0.700 (works fine with 0.670)

wherein the author of the issue originally ran mypy with the following line

RUN mypy --strict ./mypackage/tests.py

and solved the problem by running mypy by adding on the --implicit-reexport flag as follows:

RUN mypy --strict --implicit-reexport ./mypackage/tests.py

evantkchong
  • 2,251
  • 3
  • 14
  • 29