mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-16 17:19:52 +00:00
change keyword_arguments_for so it does not modify and return
This commit is contained in:
parent
969e8f38d3
commit
f9eb0fd6ea
3 changed files with 16 additions and 15 deletions
|
|
@ -340,13 +340,15 @@ class FileChecker:
|
||||||
LOG.debug("Running %r with %r", plugin, arguments)
|
LOG.debug("Running %r with %r", plugin, arguments)
|
||||||
assert self.processor is not None
|
assert self.processor is not None
|
||||||
try:
|
try:
|
||||||
self.processor.keyword_arguments_for(plugin.parameters, arguments)
|
params = self.processor.keyword_arguments_for(
|
||||||
|
plugin.parameters, arguments
|
||||||
|
)
|
||||||
except AttributeError as ae:
|
except AttributeError as ae:
|
||||||
raise exceptions.PluginRequestedUnknownParameters(
|
raise exceptions.PluginRequestedUnknownParameters(
|
||||||
plugin_name=plugin.display_name, exception=ae
|
plugin_name=plugin.display_name, exception=ae
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
return plugin.obj(**arguments)
|
return plugin.obj(**arguments, **params)
|
||||||
except Exception as all_exc:
|
except Exception as all_exc:
|
||||||
LOG.critical(
|
LOG.critical(
|
||||||
"Plugin %s raised an unexpected exception",
|
"Plugin %s raised an unexpected exception",
|
||||||
|
|
|
||||||
|
|
@ -241,16 +241,15 @@ class FileProcessor:
|
||||||
def keyword_arguments_for(
|
def keyword_arguments_for(
|
||||||
self,
|
self,
|
||||||
parameters: Dict[str, bool],
|
parameters: Dict[str, bool],
|
||||||
arguments: Optional[Dict[str, Any]] = None,
|
arguments: Dict[str, Any],
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""Generate the keyword arguments for a list of parameters."""
|
"""Generate the keyword arguments for a list of parameters."""
|
||||||
if arguments is None:
|
ret = {}
|
||||||
arguments = {}
|
|
||||||
for param, required in parameters.items():
|
for param, required in parameters.items():
|
||||||
if param in arguments:
|
if param in arguments:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
arguments[param] = getattr(self, param)
|
ret[param] = getattr(self, param)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
if required:
|
if required:
|
||||||
raise
|
raise
|
||||||
|
|
@ -260,7 +259,7 @@ class FileProcessor:
|
||||||
"but this is not an available parameter.",
|
"but this is not an available parameter.",
|
||||||
param,
|
param,
|
||||||
)
|
)
|
||||||
return arguments
|
return ret
|
||||||
|
|
||||||
def generate_tokens(self) -> Generator[tokenize.TokenInfo, None, None]:
|
def generate_tokens(self) -> Generator[tokenize.TokenInfo, None, None]:
|
||||||
"""Tokenize the file and yield the tokens."""
|
"""Tokenize the file and yield the tokens."""
|
||||||
|
|
|
||||||
|
|
@ -209,21 +209,21 @@ def test_next_line(default_options):
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
{"blank_before": True, "blank_lines": True},
|
{"blank_before": True, "blank_lines": True},
|
||||||
None,
|
{},
|
||||||
{"blank_before": 0, "blank_lines": 0},
|
{"blank_before": 0, "blank_lines": 0},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
{"noqa": True, "fake": True},
|
{"noqa": True, "fake": True},
|
||||||
{"fake": "foo"},
|
{"fake": "foo"},
|
||||||
{"noqa": False, "fake": "foo"},
|
{"noqa": False},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
{"blank_before": True, "blank_lines": True, "noqa": True},
|
{"blank_before": True, "blank_lines": True, "noqa": True},
|
||||||
{"blank_before": 10, "blank_lines": 5, "noqa": True},
|
{"blank_before": 10, "blank_lines": 5, "noqa": True},
|
||||||
{"blank_before": 10, "blank_lines": 5, "noqa": True},
|
{},
|
||||||
),
|
),
|
||||||
({}, {"fake": "foo"}, {"fake": "foo"}),
|
({}, {"fake": "foo"}, {}),
|
||||||
({"non-existent": False}, {"fake": "foo"}, {"fake": "foo"}),
|
({"non-existent": False}, {"fake": "foo"}, {}),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_keyword_arguments_for(params, args, expected_kwargs, default_options):
|
def test_keyword_arguments_for(params, args, expected_kwargs, default_options):
|
||||||
|
|
@ -235,9 +235,9 @@ def test_keyword_arguments_for(params, args, expected_kwargs, default_options):
|
||||||
"Line 1",
|
"Line 1",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
kwargs_for = file_processor.keyword_arguments_for
|
ret = file_processor.keyword_arguments_for(params, args)
|
||||||
|
|
||||||
assert kwargs_for(params, args) == expected_kwargs
|
assert ret == expected_kwargs
|
||||||
|
|
||||||
|
|
||||||
def test_keyword_arguments_for_does_not_handle_attribute_errors(
|
def test_keyword_arguments_for_does_not_handle_attribute_errors(
|
||||||
|
|
@ -253,7 +253,7 @@ def test_keyword_arguments_for_does_not_handle_attribute_errors(
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(AttributeError):
|
with pytest.raises(AttributeError):
|
||||||
file_processor.keyword_arguments_for({"fake": True})
|
file_processor.keyword_arguments_for({"fake": True}, {})
|
||||||
|
|
||||||
|
|
||||||
def test_processor_split_line(default_options):
|
def test_processor_split_line(default_options):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue