mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-29 18:46:52 +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):
|
||||
"""argparse action to print debug information."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, *args, option_manager, **kwargs):
|
||||
"""Initialize the action.
|
||||
|
||||
This takes an extra `option_manager` keyword argument which will be
|
||||
used to delay response.
|
||||
"""
|
||||
self._option_manager = kwargs.pop("option_manager")
|
||||
self._option_manager = option_manager
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
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):
|
||||
"""Shim for optparse-style callback actions."""
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
self._callback = kwargs.pop("callback")
|
||||
self._callback_args = kwargs.pop("callback_args", ())
|
||||
self._callback_kwargs = kwargs.pop("callback_kwargs", {})
|
||||
def __init__(
|
||||
self,
|
||||
*args: Any,
|
||||
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)
|
||||
|
||||
def __call__(
|
||||
|
|
@ -71,13 +78,11 @@ class _CallbackAction(argparse.Action):
|
|||
|
||||
|
||||
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]]:
|
||||
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
|
||||
if comma_separated_list and isinstance(ret, str):
|
||||
ret = utils.parse_comma_separated_list(value)
|
||||
|
|
|
|||
|
|
@ -11,14 +11,12 @@ DEFAULT_TEXT = "Default text"
|
|||
|
||||
def make_error(**kwargs):
|
||||
"""Create errors with a bunch of default values."""
|
||||
return style_guide.Violation(
|
||||
code=kwargs.pop("code", DEFAULT_ERROR_CODE),
|
||||
filename=kwargs.pop("filename", DEFAULT_FILENAME),
|
||||
line_number=kwargs.pop("line_number", 1),
|
||||
column_number=kwargs.pop("column_number", 1),
|
||||
text=kwargs.pop("text", DEFAULT_TEXT),
|
||||
physical_line=None,
|
||||
)
|
||||
kwargs.setdefault("code", DEFAULT_ERROR_CODE)
|
||||
kwargs.setdefault("filename", DEFAULT_FILENAME)
|
||||
kwargs.setdefault("line_number", 1)
|
||||
kwargs.setdefault("column_number", 1)
|
||||
kwargs.setdefault("text", DEFAULT_TEXT)
|
||||
return style_guide.Violation(**kwargs, physical_line=None)
|
||||
|
||||
|
||||
def test_key_creation():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue