mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 22:34:17 +00:00
replace py2-kwonly shim with true kwonly args
This commit is contained in:
parent
1675ddafa1
commit
3b7dbd6697
3 changed files with 23 additions and 20 deletions
|
|
@ -9,13 +9,13 @@ from typing import List
|
||||||
class DebugAction(argparse.Action):
|
class DebugAction(argparse.Action):
|
||||||
"""argparse action to print debug information."""
|
"""argparse action to print debug information."""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, option_manager, **kwargs):
|
||||||
"""Initialize the action.
|
"""Initialize the action.
|
||||||
|
|
||||||
This takes an extra `option_manager` keyword argument which will be
|
This takes an extra `option_manager` keyword argument which will be
|
||||||
used to delay response.
|
used to delay response.
|
||||||
"""
|
"""
|
||||||
self._option_manager = kwargs.pop("option_manager")
|
self._option_manager = option_manager
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,17 @@ _optparse_callable_map: Dict[str, Union[Type[Any], _ARG]] = {
|
||||||
class _CallbackAction(argparse.Action):
|
class _CallbackAction(argparse.Action):
|
||||||
"""Shim for optparse-style callback actions."""
|
"""Shim for optparse-style callback actions."""
|
||||||
|
|
||||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
def __init__(
|
||||||
self._callback = kwargs.pop("callback")
|
self,
|
||||||
self._callback_args = kwargs.pop("callback_args", ())
|
*args: Any,
|
||||||
self._callback_kwargs = kwargs.pop("callback_kwargs", {})
|
callback: Callable[..., Any],
|
||||||
|
callback_args: Sequence[Any] = (),
|
||||||
|
callback_kwargs: Optional[Dict[str, Any]] = None,
|
||||||
|
**kwargs: Any,
|
||||||
|
) -> None:
|
||||||
|
self._callback = callback
|
||||||
|
self._callback_args = callback_args
|
||||||
|
self._callback_kwargs = callback_kwargs or {}
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def __call__(
|
def __call__(
|
||||||
|
|
@ -71,13 +78,11 @@ class _CallbackAction(argparse.Action):
|
||||||
|
|
||||||
|
|
||||||
def _flake8_normalize(
|
def _flake8_normalize(
|
||||||
value: str, *args: str, **kwargs: bool
|
value: str,
|
||||||
|
*args: str,
|
||||||
|
comma_separated_list: bool = False,
|
||||||
|
normalize_paths: bool = False,
|
||||||
) -> Union[str, List[str]]:
|
) -> Union[str, List[str]]:
|
||||||
comma_separated_list = kwargs.pop("comma_separated_list", False)
|
|
||||||
normalize_paths = kwargs.pop("normalize_paths", False)
|
|
||||||
if kwargs:
|
|
||||||
raise TypeError(f"Unexpected keyword args: {kwargs}")
|
|
||||||
|
|
||||||
ret: Union[str, List[str]] = value
|
ret: Union[str, List[str]] = value
|
||||||
if comma_separated_list and isinstance(ret, str):
|
if comma_separated_list and isinstance(ret, str):
|
||||||
ret = utils.parse_comma_separated_list(value)
|
ret = utils.parse_comma_separated_list(value)
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,12 @@ DEFAULT_TEXT = "Default text"
|
||||||
|
|
||||||
def make_error(**kwargs):
|
def make_error(**kwargs):
|
||||||
"""Create errors with a bunch of default values."""
|
"""Create errors with a bunch of default values."""
|
||||||
return style_guide.Violation(
|
kwargs.setdefault("code", DEFAULT_ERROR_CODE)
|
||||||
code=kwargs.pop("code", DEFAULT_ERROR_CODE),
|
kwargs.setdefault("filename", DEFAULT_FILENAME)
|
||||||
filename=kwargs.pop("filename", DEFAULT_FILENAME),
|
kwargs.setdefault("line_number", 1)
|
||||||
line_number=kwargs.pop("line_number", 1),
|
kwargs.setdefault("column_number", 1)
|
||||||
column_number=kwargs.pop("column_number", 1),
|
kwargs.setdefault("text", DEFAULT_TEXT)
|
||||||
text=kwargs.pop("text", DEFAULT_TEXT),
|
return style_guide.Violation(**kwargs, physical_line=None)
|
||||||
physical_line=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_key_creation():
|
def test_key_creation():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue