Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mypy gives an error while importing submodule : Module has no attribute

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.

like image 941
Liya Avatar asked Dec 17 '25 18:12

Liya


1 Answers

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

like image 111
evantkchong Avatar answered Dec 20 '25 10:12

evantkchong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!