Skip to content

Add typing to two utility functions #6111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions pylint/config/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@


import re
from typing import Callable, Dict, List, Optional, Pattern, Union
from typing import Callable, Dict, List, Optional, Pattern, Sequence, Union

from pylint import utils as pylint_utils

_ArgumentTypes = Union[str, List[str], int, Pattern[str]]
_ArgumentTypes = Union[str, Sequence[str], int, Pattern[str]]
"""List of possible argument types."""


def _csv_transformer(value: str) -> List[str]:
def _csv_transformer(value: str) -> Sequence[str]:
"""Transforms a comma separated string."""
return pylint_utils._check_csv(value)

Expand Down
10 changes: 5 additions & 5 deletions pylint/reporters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def colorize_ansi(
def colorize_ansi(
msg: str,
msg_style: Optional[str] = None,
style: Optional[str] = None,
style: str = "",
*,
color: Optional[str] = None,
) -> str:
Expand All @@ -119,7 +119,7 @@ def colorize_ansi(
def colorize_ansi(
msg: str,
msg_style: Union[MessageStyle, str, None] = None,
style: Optional[str] = None,
style: str = "",
**kwargs: Optional[str],
) -> str:
r"""colorize message by wrapping it with ansi escape codes
Expand Down Expand Up @@ -267,7 +267,7 @@ def __init__(
def __init__(
self,
output: Optional[TextIO] = None,
color_mapping: Optional[Dict[str, Tuple[Optional[str], Optional[str]]]] = None,
color_mapping: Optional[Dict[str, Tuple[Optional[str], str]]] = None,
) -> None:
# Remove for pylint 3.0
...
Expand All @@ -276,7 +276,7 @@ def __init__(
self,
output: Optional[TextIO] = None,
color_mapping: Union[
ColorMappingDict, Dict[str, Tuple[Optional[str], Optional[str]]], None
ColorMappingDict, Dict[str, Tuple[Optional[str], str]], None
] = None,
) -> None:
super().__init__(output)
Expand All @@ -292,7 +292,7 @@ def __init__(
temp_color_mapping: ColorMappingDict = {}
for key, value in color_mapping.items():
color = value[0]
style_attrs = tuple(_splitstrip(value[1]))
style_attrs = tuple(_splitstrip(value[1])) # type: ignore[arg-type]
temp_color_mapping[key] = MessageStyle(color, style_attrs)
color_mapping = temp_color_mapping
else:
Expand Down
5 changes: 3 additions & 2 deletions pylint/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
List,
Optional,
Pattern,
Sequence,
TextIO,
Tuple,
TypeVar,
Expand Down Expand Up @@ -276,7 +277,7 @@ def get_global_option(
return default


def _splitstrip(string, sep=","):
def _splitstrip(string: str, sep: str = ",") -> List[str]:
"""Return a list of stripped string by splitting the string given as
argument on `sep` (',' by default), empty strings are discarded.

Expand Down Expand Up @@ -314,7 +315,7 @@ def _unquote(string: str) -> str:
return string


def _check_csv(value):
def _check_csv(value: Union[List[str], Tuple[str], str]) -> Sequence[str]:
if isinstance(value, (list, tuple)):
return value
return _splitstrip(value)
Expand Down