Skip to content
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

mypy should search parent directories for pyproject.toml config file #10613

Open
benburk opened this issue Jun 9, 2021 · 7 comments · May be fixed by #16965
Open

mypy should search parent directories for pyproject.toml config file #10613

benburk opened this issue Jun 9, 2021 · 7 comments · May be fixed by #16965
Labels
bug mypy got something wrong topic-configuration Configuration files and flags

Comments

@benburk
Copy link

benburk commented Jun 9, 2021

Bug Report

First of all, thank you for supporting the highly requested pyproject.toml config format #5205

I'm hoping we can resolve an issue to bring mypy inline with several others including but not limited to isort, black, and pylint. I think mypy should search parent directories for pyproject.toml config file. I think mypy should search up until the user's home directory (or ~25 directories, whichever comes first) for config files.

To Reproduce

Prepare a project such as this

outer/
    inner/
        main.py
    pyproject.toml

From inside the inner directory, run mypy main.py

Expected Behavior

I expect mypy to use the settings defined in the pyproject.toml file found in the parent directory outer. I'm guessing mypy only checks the directory it is invoked from.

Actual Behavior

The settings inside pyproject.toml are not used.

Your Environment

  • Mypy version used: 0.900
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.9.4
  • Operating system and version: macOS 10.15
@benburk benburk added the bug mypy got something wrong label Jun 9, 2021
@yeputons
Copy link

yeputons commented Nov 2, 2021

A four-year old related discussion about setup.cfg is available at #3377 (comment)

@AlexWaygood AlexWaygood added the topic-configuration Configuration files and flags label Mar 31, 2022
@Felixoid
Copy link

Hello.

As far as I understand the meaning of pyproject.toml it's supposed to be a global project configuration.

Why should one set the config file manually or have meaningless symlinks everywhere when working in subdirectories?

Another good approach would be to set a stop for a project directory like it's done in black

@zyxkad
Copy link

zyxkad commented Mar 2, 2023

I saw the comment at #3377 (comment).
It's a good point of view. I suggest mypy should stop search the configs when find .git directory or others VCS cache.
Will that help? @gvanrossum

Edit: I reviewed this comment, and I found I misunderstood you. You think the config will affect the subdirectories, that's true, but we actually want that affect subdirs. You don't need worried about different act about check parents or not (probably you can add a flag on the pyproject.toml to enable parent search if you really worried about it). If people want specific check, they should always write a config in that dir, or always add flags to their check command.

@Felixoid
Copy link

Felixoid commented Feb 26, 2024

Dear @hauntsaninja, @ilevkivskyi, @AlexWaygood and @JukkaL, mentioning you as top 4

If I'd try to implement it somewhere around this line, would you consider reviewing the PR?

It could have the same fuse as pylint, so won't leave the repository in case of .git or .hg directory is presented

@ilevkivskyi
Copy link
Member

I can't guarantee I will have time to review the PR, but if it is straightforward, there is high chance that either me or someone else will review it.

@Felixoid
Copy link

Ok, here's the first shot #16965

It's exactly how it's done in the pylint, but with os.path instead of pathlibPath

@Felixoid
Copy link

It's already three months since the PR is created =(

And, coincidentally, it's my birthday today. It would be a good present to review the code ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-configuration Configuration files and flags
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants