@@ -278,8 +278,10 @@ def init(workspace: str) -> Dict[str, str]:
278
278
279
279
mypyConfigFile = findConfigFile (workspace , ["mypy.ini" , ".mypy.ini" ])
280
280
mypyConfigFileMap [workspace ] = mypyConfigFile
281
+ if mypyConfigFileMap [workspace ] is None :
282
+ mypyConfigFileMap [workspace ] = defaultMypyConfigFile ()
281
283
282
- log .info ("mypyConfigFile = %s configuration = %s" , mypyConfigFile , configuration )
284
+ log .info ("mypyConfigFile = %s configuration = %s" , mypyConfigFileMap [ workspace ] , configuration )
283
285
return configuration
284
286
285
287
@@ -320,6 +322,30 @@ def findConfigFile(path: str, names: List[str]) -> Optional[str]:
320
322
return None
321
323
322
324
325
+ def defaultMypyConfigFile () -> Optional [str ]:
326
+ """
327
+ Find the mypy default config file path defined in the mypy document below.
328
+
329
+ Reference: https://mypy.readthedocs.io/en/stable/config_file.html
330
+
331
+ Returns
332
+ -------
333
+ Optional[str]
334
+ The path where the default config file has been found or None if no matching file has been found.
335
+
336
+ """
337
+ # A list of user default config file path
338
+ user_default_config = ["~/.config/mypy/config" , "~/.mypy.ini" ]
339
+ if os .environ .get ("XDG_CONFIG_HOME" ):
340
+ user_default_config .insert (0 , os .path .join (os .environ ["XDG_CONFIG_HOME" ], "mypy/config" ))
341
+
342
+ for config_file in user_default_config :
343
+ if Path (config_file ).expanduser ().exists ():
344
+ return config_file
345
+
346
+ return None
347
+
348
+
323
349
@atexit .register
324
350
def close () -> None :
325
351
"""
0 commit comments