Error importing plugin 'mypy_django_plugin.main'

See original GitHub issue

(As per #160, I’m forking a dedicated issue for this.)

I’m using mypy 0.720 with django-stubs 1.1.0 (from PyPI today):

$ mypy --version
mypy 0.720
$ pip show django-stubs
Name: django-stubs
Version: 1.1.0

With plugins = mypy_django_plugin.main in mypy.ini, mypy fails as follows:

mypy -p foo.bar
../mypy.ini:12: error: Error importing plugin 'mypy_django_plugin.main'

even though mypy_django_plugin loads just fine.

I’ve tried dropping .main from the mypy.ini and that gives:

../mypy.ini:12: error: Plugin 'mypy_django_plugin' does not define entry point function "plugin"

I’ve also tried replacing .main with :main (which seems to be the current recommended way to specify entry points in mypy.ini) and that gives:

../mypy.ini:12: error: Plugin 'mypy_django_plugin' does not define entry point function "main"

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
ibraraslamcommented, Oct 31, 2019

was facing the same issue, but placing [mypy.plugins.django-stubs] before setting plugins in setup.cfg fixed it for me.

2reactions
sklarsacommented, Dec 19, 2019

I’m able to repro this in Django v2 as well.

This happens at module import time, before the DjangoContext gets initialized (and sets up django). A hacky fix is to move the ArrayField import block inside the DjangoContext.__init__ func after the initialize_django call. This works because the class is only referenced inside an instantiated version of the class. Although I admit, this is not a viable long-term solution.

An example of this is here: https://github.com/typeddjango/django-stubs/compare/master...sklarsa:issue-166

Read more comments on GitHub >

github_iconTop Results From Across the Web

mypy-django/Lobby - Gitter
Hi guys, setting up mypy-django, i get this error. Error importing plugin 'mypy_django_plugin.main'. done just pip install and added mypy_django_plugin.main ...
Read more >
MyPy, VSCode, Django, ModuleNotFound - Stack Overflow
BTW, it works if I run MyPy in terminal. Error: ModuleNotFoundError: No module named 'my_project.settings'. mypy.ini: [mypy] plugins = ...
Read more >
django-stubs - PyPI
[mypy] plugins = mypy_django_plugin.main [mypy.plugins.django-stubs] ... You can also run mypy with --tb option to get extra information about the error.
Read more >
Type Check Your Django Application - Technical Ramblings
The talk was about adding Python gradual typing to Django using ... false plugins = mypy_django_plugin.main, [mypy.plugins.django-stubs] ...
Read more >
Mypy Plugin: PEP-484 Stubs for Django - Morioh
[mypy] plugins = mypy_django_plugin.main [mypy.plugins.django-stubs] ... from typing import TypedDict from django_stubs_ext import WithAnnotations from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found