mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 23:04:18 +00:00
Merge pull request #1489 from asottile/exceptions-plugin-name
use plugin_name= instead of dicts in exceptions
This commit is contained in:
commit
fed77cd60a
3 changed files with 12 additions and 13 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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!"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue