diff options
author | Anthony Sottile <asottile@umich.edu> | 2021-12-07 15:36:20 -0800 |
---|---|---|
committer | Anthony Sottile <asottile@umich.edu> | 2021-12-07 15:36:20 -0800 |
commit | 1e4743d490040c320b0c453edca15f90c7bf1bc7 (patch) | |
tree | cb4beed6333f4097d5d99a62da25eb8197bcd3fe | |
parent | 0f1825fdbe0bff55975800b88a66e21be26ad179 (diff) | |
download | flake8-1e4743d490040c320b0c453edca15f90c7bf1bc7.tar.gz |
use plugin_name= instead of dicts in exceptions
-rw-r--r-- | src/flake8/checker.py | 4 | ||||
-rw-r--r-- | src/flake8/exceptions.py | 17 | ||||
-rw-r--r-- | tests/unit/test_exceptions.py | 4 |
3 files changed, 12 insertions, 13 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py index d093f39..63fa439 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -353,7 +353,7 @@ class FileChecker: except AttributeError as ae: LOG.error("Plugin requested unknown parameters.") raise exceptions.PluginRequestedUnknownParameters( - plugin=plugin, exception=ae + plugin_name=plugin["plugin_name"], exception=ae ) try: return plugin["plugin"](**arguments) @@ -364,7 +364,7 @@ class FileChecker: exc_info=True, ) raise exceptions.PluginExecutionFailed( - plugin=plugin, exception=all_exc + plugin_name=plugin["plugin_name"], exception=all_exc ) @staticmethod diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py index 45db94d..e2dfd77 100644 --- a/src/flake8/exceptions.py +++ b/src/flake8/exceptions.py @@ -1,5 +1,4 @@ """Exception classes for all of Flake8.""" -from typing import Dict class Flake8Exception(Exception): @@ -38,16 +37,16 @@ class PluginRequestedUnknownParameters(Flake8Exception): 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.""" - self.plugin = plugin + self.plugin_name = plugin_name self.original_exception = exception - super().__init__(plugin, exception) + super().__init__(plugin_name, exception) def __str__(self) -> str: """Format our exception message.""" return self.FORMAT % { - "name": self.plugin["plugin_name"], + "name": self.plugin_name, "exc": self.original_exception, } @@ -57,15 +56,15 @@ class PluginExecutionFailed(Flake8Exception): 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.""" - self.plugin = plugin + self.plugin_name = plugin_name self.original_exception = exception - super().__init__(plugin, exception) + super().__init__(plugin_name, exception) def __str__(self) -> str: """Format our exception message.""" return self.FORMAT % { - "name": self.plugin["plugin_name"], + "name": self.plugin_name, "exc": self.original_exception, } diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py index 6be1ebd..06c5179 100644 --- a/tests/unit/test_exceptions.py +++ b/tests/unit/test_exceptions.py @@ -14,11 +14,11 @@ from flake8 import exceptions exception=ValueError("boom!"), ), exceptions.PluginRequestedUnknownParameters( - plugin={"plugin_name": "plugin_name"}, + plugin_name="plugin_name", exception=ValueError("boom!"), ), exceptions.PluginExecutionFailed( - plugin={"plugin_name": "plugin_name"}, + plugin_name="plugin_name", exception=ValueError("boom!"), ), ), |