Skip to content

Commit 5ee02cd

Browse files
authored
Allow trailing commas for files setting in mypy.ini and setup.ini (#18621)
Now ```ini files = a.py, b.py ``` and ```ini files = a.py, b.py, ``` will be the same thing. Previously, adding a traling comma would add `''` to `paths`, which resulted in a strange error like: ``` a.py: error: Duplicate module named "a" (also at "a.py") (diff) a.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info (diff) a.py: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATH (diff) ``` Refs #14240 Refs python/cpython#129708
1 parent fc991a0 commit 5ee02cd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

mypy/config_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def split_and_match_files(paths: str) -> list[str]:
126126
Returns a list of file paths
127127
"""
128128

129-
return split_and_match_files_list(paths.split(","))
129+
return split_and_match_files_list(split_commas(paths))
130130

131131

132132
def check_follow_imports(choice: str) -> str:

test-data/unit/cmdline.test

+16
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,22 @@ foo.py:1: error: "int" not callable
13001300
[out]
13011301
foo/m.py:1: error: "int" not callable
13021302

1303+
[case testCmdlineCfgFilesTrailingComma]
1304+
# cmd: mypy
1305+
[file mypy.ini]
1306+
\[mypy]
1307+
files =
1308+
a.py,
1309+
b.py,
1310+
[file a.py]
1311+
x: str = 'x' # ok
1312+
[file b.py]
1313+
y: int = 'y' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
1314+
[file c.py]
1315+
# This should not trigger any errors, because it is not included:
1316+
z: int = 'z'
1317+
[out]
1318+
13031319
[case testCmdlineCfgEnableErrorCodeTrailingComma]
13041320
# cmd: mypy .
13051321
[file mypy.ini]

0 commit comments

Comments
 (0)