Mypy: Reading mypy.ini or setup.cfg in parent directories.

Created on 17 May 2017  路  3Comments  路  Source: python/mypy

I have a folder structure like this:

foo\
  src\a.py
  test\test_a.py

I'm also using flycheck/mypy to check my files in emacs, however, it only read mypy.ini from current folder,
which is the file that I'm visiting.

I'm wondering if we can let mypy read config file from current folder, parent folder, grandparent folder etc until it find one. This is the same way of git looking for .gitignore, and nodejs looking for node_modules.

If you think it's a good idea, I might be able to write the code and make a PR.

Regards.

Most helpful comment

This is frustrating me currently. One use case for this is using mypy in an IDE to type check while coding. In order to get it working, you'd have to do something like symlink your mypy.ini files to all directories.

I don't understand your concern about a mypy.ini in your home directory. It seems to me that this is essentially the same as the one in your ~/.config/ dir. They're both hidden and affect all mypy invocations.

All 3 comments

I'm not sure whether mypy would work from those subdirectories because of how imports are resolved. Based on my experience it's better to typecheck the project as a whole, with current directory set to top project directory.

I considered this when I first implemented the config file, but I don't think that is a good idea. Most projects don't have a mypy.ini or setup.cfg file and I don't want some file by that name in e.g. my home directory to affect mypy's behavior in all subdirectories. It's easy to forget that that file exists and easy to be confused by some of the many flags that could be present in such a file.

This is frustrating me currently. One use case for this is using mypy in an IDE to type check while coding. In order to get it working, you'd have to do something like symlink your mypy.ini files to all directories.

I don't understand your concern about a mypy.ini in your home directory. It seems to me that this is essentially the same as the one in your ~/.config/ dir. They're both hidden and affect all mypy invocations.

Was this page helpful?
0 / 5 - 0 ratings