Skip to content

How to configure mypy_path for my local imports? #7389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gonzaloamadio opened this issue Aug 26, 2019 · 5 comments
Closed

How to configure mypy_path for my local imports? #7389

gonzaloamadio opened this issue Aug 26, 2019 · 5 comments

Comments

@gonzaloamadio
Copy link

Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
  • What is the actual behavior/output?
  • What is the behavior/output you expect?
  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?
  • What are the mypy flags you are using? (For example --strict-optional)
  • If mypy crashed with a traceback, please paste
    the full traceback below.

(You can freely edit this text, please remove all the lines
you believe are unnecessary.)

@gonzaloamadio
Copy link
Author

My layout

~/Playground/classroom/
    __init__.py
    app/
        quizzes.py
        utils.py
        __init__.py

Inside quizzes.py I have from classroom.app.utils import myfoo

And when I run (inside classroom folder) $ mypy app/quizzes.py

I got the error app/quizzes.py:13: error: Cannot find module named 'classroom.app.utils'

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 27, 2019

The key seems to be the current working directory. If I type check the code using mypy classroom/app/quizzes.py it works as expected.

Mypy should probably find the root of the package hierarchy (by looking at __init__.py files) and use the root in the module search path. This way you could run mypy in any nested package directory.

@zomglings
Copy link

Is this really a bug? Just running python app/quizzes.py from the classroom/ directory (or even python classroom/app/quizzes.py from the top-level directory) would result in the same ImportError.

I don't see why mypy should behave any differently (and unexpectedly!).

@ilevkivskyi
Copy link
Member

Yeah, this was previously discussed, and we decided to not do it, see #6660. There was added a clarification about this in the docs, see #6676. So I would propose to just close this.

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 29, 2019

Since the current behavior is already documented, I agree that this can be closed. However, I still think that mypy could do better here to help beginners. I'll create a separate issue about generating a better error messages -- we could detect the issue and ask the user to change the current working directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants