change keyword_arguments_for so it does not modify and return

This commit is contained in:
Anthony Sottile 2022-01-23 19:06:06 -05:00
parent 969e8f38d3
commit f9eb0fd6ea
3 changed files with 16 additions and 15 deletions

View file

@ -340,13 +340,15 @@ class FileChecker:
LOG.debug("Running %r with %r", plugin, arguments)
assert self.processor is not None
try:
self.processor.keyword_arguments_for(plugin.parameters, arguments)
params = self.processor.keyword_arguments_for(
plugin.parameters, arguments
)
except AttributeError as ae:
raise exceptions.PluginRequestedUnknownParameters(
plugin_name=plugin.display_name, exception=ae
)
try:
return plugin.obj(**arguments)
return plugin.obj(**arguments, **params)
except Exception as all_exc:
LOG.critical(
"Plugin %s raised an unexpected exception",

View file

@ -241,16 +241,15 @@ class FileProcessor:
def keyword_arguments_for(
self,
parameters: Dict[str, bool],
arguments: Optional[Dict[str, Any]] = None,
arguments: Dict[str, Any],
) -> Dict[str, Any]:
"""Generate the keyword arguments for a list of parameters."""
if arguments is None:
arguments = {}
ret = {}
for param, required in parameters.items():
if param in arguments:
continue
try:
arguments[param] = getattr(self, param)
ret[param] = getattr(self, param)
except AttributeError:
if required:
raise
@ -260,7 +259,7 @@ class FileProcessor:
"but this is not an available parameter.",
param,
)
return arguments
return ret
def generate_tokens(self) -> Generator[tokenize.TokenInfo, None, None]:
"""Tokenize the file and yield the tokens."""