Skip to content

Commit 096ec21

Browse files
committed
Implement quoting of comma separated values
1 parent 7f72dcc commit 096ec21

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

mypy/config_parser.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,34 @@ def parse_section(prefix: str, template: Options,
224224
return results, report_dirs
225225

226226

227+
def split_directive(s: str) -> List[str]:
228+
"""Split s on commas, except during quoted sections"""
229+
parts = []
230+
cur = [] # type: List[str]
231+
i = 0
232+
while i < len(s):
233+
if s[i] == ',':
234+
parts.append(''.join(cur).strip())
235+
cur = []
236+
elif s[i] == '"':
237+
i += 1
238+
while i < len(s) and s[i] != '"':
239+
cur.append(s[i])
240+
i += 1
241+
else:
242+
cur.append(s[i])
243+
i += 1
244+
if cur:
245+
parts.append(''.join(cur).strip())
246+
247+
return parts
248+
249+
227250
def mypy_comments_to_config_map(args: List[str], template: Options) -> Dict[str, str]:
228251
"""Rewrite the mypy comment syntax into ini file syntax"""
229252
options = {}
230253
for line in args:
231-
for entry in line.split(', '):
254+
for entry in split_directive(line):
232255
if '=' not in entry:
233256
name = entry
234257
value = None

test-data/unit/check-inline-config.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def foo() -> List: # E: Missing type parameters for generic type
2929
[builtins fixtures/list.pyi]
3030

3131
[case testInlineList]
32-
# mypy: disallow-any-generics, always-false=FOO,BAR
32+
# mypy: disallow-any-generics,always-false="FOO,BAR"
3333

3434
from typing import List
3535

0 commit comments

Comments
 (0)