@@ -268,8 +268,10 @@ def init(workspace: str) -> Dict[str, str]:
268
268
269
269
mypyConfigFile = findConfigFile (workspace , ["mypy.ini" , ".mypy.ini" ])
270
270
mypyConfigFileMap [workspace ] = mypyConfigFile
271
+ if mypyConfigFileMap [workspace ] is None :
272
+ mypyConfigFileMap [workspace ] = defaultMypyConfigFile ()
271
273
272
- log .info ("mypyConfigFile = %s configuration = %s" , mypyConfigFile , configuration )
274
+ log .info ("mypyConfigFile = %s configuration = %s" , mypyConfigFileMap [ workspace ] , configuration )
273
275
return configuration
274
276
275
277
@@ -310,6 +312,30 @@ def findConfigFile(path: str, names: List[str]) -> Optional[str]:
310
312
return None
311
313
312
314
315
+ def defaultMypyConfigFile () -> Optional [str ]:
316
+ """
317
+ Find the mypy default config file path defined in the mypy document below.
318
+
319
+ Reference: https://mypy.readthedocs.io/en/stable/config_file.html
320
+
321
+ Returns
322
+ -------
323
+ Optional[str]
324
+ The path where the default config file has been found or None if no matching file has been found.
325
+
326
+ """
327
+ # A list of user default config file path
328
+ user_default_config = ["~/.config/mypy/config" , "~/.mypy.ini" ]
329
+ if os .environ .get ("XDG_CONFIG_HOME" ):
330
+ user_default_config .insert (0 , os .path .join (os .environ ["XDG_CONFIG_HOME" ], "mypy/config" ))
331
+
332
+ for config_file in user_default_config :
333
+ if Path (config_file ).expanduser ().exists ():
334
+ return config_file
335
+
336
+ return None
337
+
338
+
313
339
@atexit .register
314
340
def close () -> None :
315
341
"""
0 commit comments