Skip to content

Reading mypy.ini or setup.cfg in parent directories. #3377

Closed

Description

@co-dh

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.

Activity

  1. miedzinski commented on May 17, 2017

    @miedzinski
    Contributor

    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.

  2. gvanrossum commented on May 18, 2017

    @gvanrossum
    Member

    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.

  3. onlyanegg commented on May 23, 2019

    @onlyanegg

    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.

  4. mihaic commented on Jun 2, 2021

    @mihaic

    Please consider revisiting this decision in light of the Python Packaging Authority switching to the src directory structure in the Python Packaging User Guide. I frequently edit files while the current directory is src and Mypy does not use the configuration file next to src.

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

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