Skip to content

Config file at ~/.mypy.ini is not used #18977

Closed

Description

@jolaf

Bug Report

I have my mypy configuration file at ~/.mypy.ini.

In that config file I have the following option:

[mypy]
cache_dir=/tmp/mypy_cache

However when I run mypy from some working directory, .mypy_cache directory gets created in that directory, which means my config file is not used.

However, if I specify path to that config file directly, it's used correctly:

$ mypy -v --config-file ~/.mypy.ini SomeFile.py

LOG:  Mypy Version:           1.15.0
LOG:  Config File:            /home/user/.mypy.ini
LOG:  Configured Executable:  /usr/bin/python3
LOG:  Current Executable:     /usr/bin/python3
LOG:  Cache Dir:              /tmp/mypy_cache
...

Unfortunately, mypy doesn't print the location of the config file it uses, or the locations where it tries to find a config file, so no more details on the problem is available.

Expected Behavior

As stated in the documentation: https://mypy.readthedocs.io/en/stable/config_file.html
~/.mypy.ini should be used if --config-file is not specified and other preferred config file locations do not exist, which it true in my case.

So I would expect the exact same behavior if --config-file ~/.mypy.ini is specified and if --config-file is not specified at all.

Actual Behavior

$ mypy -v SomeFile.py

LOG:  Mypy Version:           1.15.0
LOG:  Config File:            Default
LOG:  Configured Executable:  /usr/bin/python3
LOG:  Current Executable:     /usr/bin/python3
LOG:  Cache Dir:              .mypy_cache
...

Note Config File: Default and Cache Dir: .mypy_cache.

And indeed, ./.mypy_cache folder is created.

Your Environment

$ mypy --version
mypy 1.15.0 (compiled: yes)

$ python --version
Python 3.12.3

Activity

  1. sterliakov commented on Apr 27, 2025

    @sterliakov
    Collaborator

    Yes, user-level config file discovery was broken in 1.15.0, fixed in #18656 approx. a week after release. I confirmed that global config doesn't work in 1.15.0 and works on current master.

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

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions