clean up string_types

This commit is contained in:
Anthony Sottile 2021-03-29 18:11:37 -07:00
parent 5b9edd04ee
commit 3a85c8ce96
2 changed files with 6 additions and 9 deletions

View file

@ -82,11 +82,11 @@ def _flake8_normalize(value, *args, **kwargs):
raise TypeError(f"Unexpected keyword args: {kwargs}")
ret = value # type: Union[str, List[str]]
if comma_separated_list and isinstance(ret, utils.string_types):
if comma_separated_list and isinstance(ret, str):
ret = utils.parse_comma_separated_list(value)
if normalize_paths:
if isinstance(ret, utils.string_types):
if isinstance(ret, str):
ret = utils.normalize_path(ret, *args)
else:
ret = utils.normalize_paths(ret, *args)
@ -212,7 +212,7 @@ class Option:
nargs = 0
# optparse -> argparse for `type`
if isinstance(type, utils.string_types):
if isinstance(type, str):
LOG.warning(
"option %s: please update from optparse string `type=` to "
"argparse callable `type=` -- this will be an error in the "
@ -299,9 +299,7 @@ class Option:
def normalize(self, value, *normalize_args):
# type: (Any, *str) -> Any
"""Normalize the value based on the option configuration."""
if self.comma_separated_list and isinstance(
value, utils.string_types
):
if self.comma_separated_list and isinstance(value, str):
value = utils.parse_comma_separated_list(value)
if self.normalize_paths:

View file

@ -29,7 +29,6 @@ if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2
DIFF_HUNK_REGEXP = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$")
COMMA_SEPARATED_LIST_RE = re.compile(r"[,\s]")
LOCAL_PLUGIN_LIST_RE = re.compile(r"[,\t\n\r\f\v]")
string_types = (str, type(""))
def parse_comma_separated_list(value, regexp=COMMA_SEPARATED_LIST_RE):
@ -48,7 +47,7 @@ def parse_comma_separated_list(value, regexp=COMMA_SEPARATED_LIST_RE):
:rtype:
list
"""
assert isinstance(value, string_types), value
assert isinstance(value, str), value
separated = regexp.split(value)
item_gen = (item.strip() for item in separated)
@ -96,7 +95,7 @@ def parse_files_to_codes_mapping(value_): # noqa: C901
:param value: String to be parsed and normalized.
:type value: str
"""
if not isinstance(value_, string_types):
if not isinstance(value_, str):
value = "\n".join(value_)
else:
value = value_