8000 Question: Can't import Django app located in the same project · Issue #9135 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Question: Can't import Django app located in the same project #9135

@LanDinh

Description

@LanDinh

Project structure:

- project
|- __init__.py
|- project
 |- __init__.py
 |- settings.py
|- app1
 |- __init__.py
 |- views
  |- example_view.py
|- app2
 |- __init__.py
 |- datatypes.py

settings.py is a Django configuration file that contains both app1 and app2 in its INSTALLED_APPS.
example_view.py contains from app2 import datatypes

This works well when running the server, no problems at all. But when throwing mypy at it, I get the error project\app1\views\example_view.py:14: error: Cannot find implementation or library stub for module named 'app2'. I should add that mypy is perfectly able to find typing issues within datatypes.py itself (I've introduced errors on mistake to check that), it just doesn't realize that the module that example_view.py is trying to import is just this datatypes.py it can type check perfectly fine.

I've tried to solve this by adding mypy_path to [mypy] in my mypy.ini, but to no avail (I might not have done that correctly; I used \\127.0.0.1\X$\<path-to-project>, following the instructions at https://mypy.readthedocs.io/en/stable/config_file.html).

I'm using python 3.8.1 and mypy 0.770 and use the command mypy --strict --follow-imports=error project.

I'm not really sure what else to do, I've tried a lot of other (less sensible things), trying to get mypy to be happy... Without that import from the sibling app, everything works fine. I don't want to restrict my project to only have 1 app, as this will totally get out of hand as I add more code to it. I could of course create a superapp and have both app1 and app2 be childen of that, but I don't think that it's good practice to completely change the structure of my working project just to satisfy mypy, when all information that it needs sits there - the literally only problem is that mypy can't connect that import with that other file it successfully type checks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0