From c59770bfa2c7a95ff9cbf2acaf2ed1444c44a9f6 Mon Sep 17 00:00:00 2001 From: Dave Dalcino Date: Thu, 11 Aug 2022 21:41:55 -0700 Subject: [PATCH] Fix use of kwargs passed up AqtException inheritance tree --- aqt/exceptions.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/aqt/exceptions.py b/aqt/exceptions.py index d56fd4f..f76a6ad 100644 --- a/aqt/exceptions.py +++ b/aqt/exceptions.py @@ -18,15 +18,15 @@ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -from typing import List +from typing import List, Optional DOCS_CONFIG = "https://aqtinstall.readthedocs.io/en/stable/configuration.html#configuration" class AqtException(Exception): - def __init__(self, *args, **kwargs): - self.suggested_action: List[str] = kwargs.pop("suggested_action", []) - self.should_show_help: bool = kwargs.pop("should_show_help", False) + def __init__(self, *args, suggested_action: Optional[List[str]] = None, should_show_help: bool = False, **kwargs): + self.suggested_action: List[str] = suggested_action or [] + self.should_show_help: bool = should_show_help or False super(AqtException, self).__init__(*args, **kwargs) def __format__(self, format_spec) -> str: @@ -53,16 +53,19 @@ class ArchiveChecksumError(ArchiveDownloadError): class ChecksumDownloadFailure(ArchiveDownloadError): - def __init__(self, *args, **kwargs): - kwargs["suggested_action"] = kwargs.pop("suggested_action", []).extend( + def __init__(self, *args, suggested_action: Optional[List[str]] = None, **kwargs): + if suggested_action is None: + suggested_action = [] + suggested_action.extend( [ "Check your internet connection", "Consider modifying `requests.max_retries_to_retrieve_hash` in settings.ini", f"Consider modifying `mirrors.trusted_mirrors` in settings.ini (see {DOCS_CONFIG})", ] ) - kwargs["should_show_help"] = True - super(ChecksumDownloadFailure, self).__init__(*args, **kwargs) + super(ChecksumDownloadFailure, self).__init__( + *args, suggested_action=suggested_action, should_show_help=True, **kwargs + ) class ArchiveConnectionError(AqtException):