Skip to content

Implement monorepo-friendly mypy.ini discovery rule #16070

Closed

Description

@sfc-gh-bwarsaw

Feature

Enhance mypy's mypy.ini discovery rules to look in ancestor directories, in the same way that ruff looks for its ruff.toml file.

Pitch

Let's say I'm working in a monorepo, where subpackages live next to each other in a file system layout similar to this:

README.md
# other monorepo top level files
ruff.toml
libs/
    subpackageA/
        pyproject.toml
        mypy.ini
        src/
        tests/
        docs/
    subpackageB/
        pyproject.toml
        mypy.ini
        src/
        tests/
        docs/
...

When I cd libs/subpackageA to do development work in just subpackageA, I would like for my type checking to be driven by a common mypy.ini file, at the top level of my repo. However, mypy won't walk up the filesystem to discover the mypy.ini file at the top-level. Contrast that with ruff's discovery rules which do walk up the filesystem until it finds a ruff.toml file.

There are workarounds: 1) symlink the subprojects's mypy.ini to the root level mypy.ini; 2) copy the same mypy.ini file into each subpackage directory. Neither option is all that great. A rule similar to ruff's would let me eliminate the symlinks and move the mypy.ini file to the root of my repo, so that its settings can be easily shared across all subpackages in my monorepo.

Activity

  1. michealroberts commented on Mar 13, 2024

    @michealroberts

    Could the priority on this be bumped please, we have a pressing need for mypy to play a little nicer with monorepos.

    Currently, I am unsure as to why mypy cannot follow the same rules as Python ... could someone explain to me why this is not possible?

  2. Goldziher commented on Sep 15, 2024

    @Goldziher

    +1

  3. added a commit that references this issue on Jan 20, 2025
    42a97bb
  4. added a commit that references this issue on Jan 22, 2025
    33f60e4
  5. added a commit that references this issue on Feb 24, 2025
    ec07630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions