From 1e4743d490040c320b0c453edca15f90c7bf1bc7 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 7 Dec 2021 15:36:20 -0800 Subject: [PATCH] use plugin_name= instead of dicts in exceptions --- src/flake8/checker.py | 4 ++-- src/flake8/exceptions.py | 17 ++++++++--------- 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!"), ), ),