Merge pull request #1489 from asottile/exceptions-plugin-name

use plugin_name= instead of dicts in exceptions
This commit is contained in:
Anthony Sottile 2021-12-07 18:39:11 -05:00 committed by GitHub
commit fed77cd60a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 13 deletions

View file

@ -353,7 +353,7 @@ class FileChecker:
except AttributeError as ae: except AttributeError as ae:
LOG.error("Plugin requested unknown parameters.") LOG.error("Plugin requested unknown parameters.")
raise exceptions.PluginRequestedUnknownParameters( raise exceptions.PluginRequestedUnknownParameters(
plugin=plugin, exception=ae plugin_name=plugin["plugin_name"], exception=ae
) )
try: try:
return plugin["plugin"](**arguments) return plugin["plugin"](**arguments)
@ -364,7 +364,7 @@ class FileChecker:
exc_info=True, exc_info=True,
) )
raise exceptions.PluginExecutionFailed( raise exceptions.PluginExecutionFailed(
plugin=plugin, exception=all_exc plugin_name=plugin["plugin_name"], exception=all_exc
) )
@staticmethod @staticmethod

View file

@ -1,5 +1,4 @@
"""Exception classes for all of Flake8.""" """Exception classes for all of Flake8."""
from typing import Dict
class Flake8Exception(Exception): class Flake8Exception(Exception):
@ -38,16 +37,16 @@ class PluginRequestedUnknownParameters(Flake8Exception):
FORMAT = '"%(name)s" requested unknown parameters causing %(exc)s' FORMAT = '"%(name)s" requested unknown parameters causing %(exc)s'
def __init__(self, plugin: Dict[str, str], exception: Exception) -> None: def __init__(self, plugin_name: str, exception: Exception) -> None:
"""Pop certain keyword arguments for initialization.""" """Pop certain keyword arguments for initialization."""
self.plugin = plugin self.plugin_name = plugin_name
self.original_exception = exception self.original_exception = exception
super().__init__(plugin, exception) super().__init__(plugin_name, exception)
def __str__(self) -> str: def __str__(self) -> str:
"""Format our exception message.""" """Format our exception message."""
return self.FORMAT % { return self.FORMAT % {
"name": self.plugin["plugin_name"], "name": self.plugin_name,
"exc": self.original_exception, "exc": self.original_exception,
} }
@ -57,15 +56,15 @@ class PluginExecutionFailed(Flake8Exception):
FORMAT = '"%(name)s" failed during execution due to "%(exc)s"' FORMAT = '"%(name)s" failed during execution due to "%(exc)s"'
def __init__(self, plugin: Dict[str, str], exception: Exception) -> None: def __init__(self, plugin_name: str, exception: Exception) -> None:
"""Utilize keyword arguments for message generation.""" """Utilize keyword arguments for message generation."""
self.plugin = plugin self.plugin_name = plugin_name
self.original_exception = exception self.original_exception = exception
super().__init__(plugin, exception) super().__init__(plugin_name, exception)
def __str__(self) -> str: def __str__(self) -> str:
"""Format our exception message.""" """Format our exception message."""
return self.FORMAT % { return self.FORMAT % {
"name": self.plugin["plugin_name"], "name": self.plugin_name,
"exc": self.original_exception, "exc": self.original_exception,
} }

View file

@ -14,11 +14,11 @@ from flake8 import exceptions
exception=ValueError("boom!"), exception=ValueError("boom!"),
), ),
exceptions.PluginRequestedUnknownParameters( exceptions.PluginRequestedUnknownParameters(
plugin={"plugin_name": "plugin_name"}, plugin_name="plugin_name",
exception=ValueError("boom!"), exception=ValueError("boom!"),
), ),
exceptions.PluginExecutionFailed( exceptions.PluginExecutionFailed(
plugin={"plugin_name": "plugin_name"}, plugin_name="plugin_name",
exception=ValueError("boom!"), exception=ValueError("boom!"),
), ),
), ),