Repository: python/mypy

Issue:
Feature request: Support XDG standard in configuration file
From docs[[1]]:

> By default [mypy] uses the file mypy.ini with fallback to setup.cfg in the current directory, or .mypy.ini in the user home directory if none of them are found; the --config-file command-line flag can be used to read a different file instead (see --config-file).


Please consider adding support for the XDG base directory specification by reading the configuration file from `$XDG_CONFIG_HOME/mypy/config` and then `$HOME/.config/mypy/config` before falling back to `$HOME/.mypy.ini`.

Further reading from freedesktop.org[[2]]:

> There is a single base directory relative to which user-specific configuration files should be written. This directory is defined by the environment variable $XDG_CONFIG_HOME.

> $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

[1]: https://mypy.readthedocs.io/en/latest/config_file.html#config-file
[2]: https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

<!--
Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues

Please provide more information to help us understand the issue:

* Are you reporting a bug, or opening a feature request?
* Please insert below the code you are checking with mypy,
  or a mock-up repro if the source is private. We would appreciate
  if you try to simplify your case to a minimal repro.
* What is the actual behavior/output?
* What is the behavior/output you expect?
* What are the versions of mypy and Python you are using?
  Do you see the same issue after installing mypy from Git master?
* What are the mypy flags you are using? (For example --strict-optional)
* If mypy crashed with a traceback, please paste
  the full traceback below.

(You can freely edit this text, please remove all the lines
you believe are unnecessary.)
-->


Discussion:
If you submit a PR we could consider it.
Ok, I'll have a look when I get some time. Thanks.

Resolving patch:
diff --git a/mypy/defaults.py b/mypy/defaults.py
--- a/mypy/defaults.py
+++ b/mypy/defaults.py
@@ -1,3 +1,5 @@
+import os
+
 MYPY = False
 if MYPY:
     from typing_extensions import Final
@@ -7,9 +9,12 @@
 PYTHON3_VERSION_MIN = (3, 4)  # type: Final
 CACHE_DIR = '.mypy_cache'  # type: Final
 CONFIG_FILE = 'mypy.ini'  # type: Final
-SHARED_CONFIG_FILES = ('setup.cfg',)  # type: Final
-USER_CONFIG_FILES = ('~/.mypy.ini',)  # type: Final
-CONFIG_FILES = (CONFIG_FILE,) + SHARED_CONFIG_FILES + USER_CONFIG_FILES  # type: Final
+SHARED_CONFIG_FILES = ['setup.cfg', ]  # type: Final
+USER_CONFIG_FILES = ['~/.config/mypy/config', '~/.mypy.ini', ]  # type: Final
+if os.environ.get('XDG_CONFIG_HOME'):
+    USER_CONFIG_FILES.insert(0, os.path.join(os.environ['XDG_CONFIG_HOME'], 'mypy/config'))
+
+CONFIG_FILES = [CONFIG_FILE, ] + SHARED_CONFIG_FILES + USER_CONFIG_FILES  # type: Final
 
 # This must include all reporters defined in mypy.report. This is defined here
 # to make reporter names available without importing mypy.report -- this speeds


Test patch: