Skip to content

Commit 10df788

Browse files
Fix #19491, crash when using enable_error_code value of wrong type in pyproject.toml
1 parent 2e5d7ee commit 10df788

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mypy/config_parser.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,19 @@ def parse_version(v: str | float) -> tuple[int, int]:
6161

6262

6363
def try_split(v: str | Sequence[str], split_regex: str = "[,]") -> list[str]:
64-
"""Split and trim a str or list of str into a list of str"""
64+
"""Split and trim a str or sequence (eg: list) of str into a list of str.
65+
Non-str elements will simply be returned untouched. This is not documented
66+
by the types but there was no type error before this bugfix, so we must be
67+
type-ignoring elsewhere. Feel free to fix that."""
6568
if isinstance(v, str):
6669
items = [p.strip() for p in re.split(split_regex, v)]
6770
if items and items[-1] == "":
6871
items.pop(-1)
6972
return items
70-
return [p.strip() for p in v]
73+
elif isinstance(v, Sequence):
74+
return [p.strip() if isinstance(p, str) else p for p in v]
75+
else:
76+
return v
7177

7278

7379
def validate_codes(codes: list[str]) -> list[str]:

0 commit comments

Comments
 (0)