Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ def parse_version(v: str | float) -> tuple[int, int]:
return major, minor


def try_split(v: str | Sequence[str], split_regex: str = "[,]") -> list[str]:
"""Split and trim a str or list of str into a list of str"""
def try_split(v: str | Sequence[str] | Any, split_regex: str = "[,]") -> list[str] | Any:
"""Split and trim a str or sequence (eg: list) of str into a list of str.
Non-str elements will simply be returned untouched. Feel free to one day
fix the typing of the calling code, and remove this caveat and Any."""
if isinstance(v, str):
items = [p.strip() for p in re.split(split_regex, v)]
if items and items[-1] == "":
items.pop(-1)
return items
return [p.strip() for p in v]
elif isinstance(v, Sequence):
return [p.strip() if isinstance(p, str) else p for p in v]
else:
return v


def validate_codes(codes: list[str]) -> list[str]:
Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -2482,3 +2482,9 @@ A = Union[C, List] # OK
-- check_untyped_defs is False by default.
def f():
x: int = "no" # N: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs

[case testPyProjectTOMLSettingOfWrongType]
# E: Invalid error code(s): true
[file pyproject.toml]
\[tool.mypy]
enable_error_code = true