From 0796cbbcf790ac70ff67960ac85ebc46a3c32682 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sat, 12 Nov 2022 14:01:22 +0100 Subject: [PATCH] Support new mypy v0.990 reports (#453) https://mypy-lang.blogspot.com/2022/11/mypy-0990-released.html No Implicit Optional Types for Arguments sys.exit() doesn't seems to handle Exception message display where print() is not, at least for mypy pre-commit autopdate --- .pre-commit-config.yaml | 4 ++-- silkaj/auth.py | 11 +++++++---- silkaj/blockchain/blocks.py | 3 +-- silkaj/money/transfer.py | 8 ++++---- silkaj/network.py | 8 +++++--- silkaj/tui.py | 4 ++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e1561f06..0d8179bc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,7 +20,7 @@ repos: - id: isort args: ["--profile", "black"] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.982 + rev: v0.990 hooks: - id: mypy - repo: https://github.com/PyCQA/pylint @@ -28,7 +28,7 @@ repos: hooks: - id: pylint - repo: https://github.com/asottile/pyupgrade - rev: v3.1.0 + rev: v3.2.2 hooks: - id: pyupgrade args: [--py37-plus] diff --git a/silkaj/auth.py b/silkaj/auth.py index ffe766d7..76c55d51 100644 --- a/silkaj/auth.py +++ b/silkaj/auth.py @@ -22,7 +22,7 @@ from click import Context, command, confirm, option, pass_context from duniterpy.key import SigningKey from duniterpy.key.scrypt_params import ScryptParams -from silkaj.constants import PUBKEY_PATTERN +from silkaj.constants import FAILURE_EXIT_STATUS, PUBKEY_PATTERN from silkaj.public_key import gen_pubkey_checksum SEED_HEX_PATTERN = "^[0-9a-fA-F]{64}$" @@ -102,7 +102,8 @@ def auth_by_seed() -> SigningKey: # To be fixed upstream in DuniterPy # pylint: disable=broad-except except Exception as error: - sys.exit(error) + print(error) + sys.exit(FAILURE_EXIT_STATUS) @pass_context @@ -127,7 +128,8 @@ def auth_by_scrypt(ctx: Context) -> SigningKey: try: return SigningKey.from_credentials(salt, password, scrypt_params) except ValueError as error: - sys.exit(error) + print(error) + sys.exit(FAILURE_EXIT_STATUS) def auth_by_wif() -> SigningKey: @@ -140,4 +142,5 @@ def auth_by_wif() -> SigningKey: # To be fixed upstream in DuniterPy # pylint: disable=broad-except except Exception as error: - sys.exit(error) + print(error) + sys.exit(FAILURE_EXIT_STATUS) diff --git a/silkaj/blockchain/blocks.py b/silkaj/blockchain/blocks.py index ed7434aa..2805dbb4 100644 --- a/silkaj/blockchain/blocks.py +++ b/silkaj/blockchain/blocks.py @@ -16,7 +16,6 @@ import time from collections import OrderedDict from operator import itemgetter -from typing import List from urllib.error import HTTPError from click import IntRange, argument, command, option @@ -95,7 +94,7 @@ def print_blocks_views(issuers, current_nbr, number, detailed): print(f"\n{table.draw()}") else: - list_issued = [] # type: List[OrderedDict] + list_issued = [] for issuer in issuers: found = False for issued in list_issued: diff --git a/silkaj/money/transfer.py b/silkaj/money/transfer.py index bf93efdd..ac016125 100644 --- a/silkaj/money/transfer.py +++ b/silkaj/money/transfer.py @@ -18,7 +18,7 @@ import math import re import shlex import time -from typing import List, Tuple +from typing import List, Optional, Tuple import click from duniterpy.api.bma.tx import process @@ -408,7 +408,7 @@ def handle_intermediaries_transactions( tx_amounts: List[int], outputAddresses: List[str], Comment: str = "", - OutputbackChange: str = None, + OutputbackChange: Optional[str] = None, ) -> None: while True: # consider there is always one backchange output, hence +1 @@ -458,7 +458,7 @@ def generate_and_send_transaction( listinput_and_amount: Tuple[List[InputSource], int, bool], outputAddresses: List[str], Comment: str, - OutputbackChange: str = None, + OutputbackChange: Optional[str] = None, ) -> None: """ Display sent transaction @@ -501,7 +501,7 @@ def generate_transaction_document( listinput_and_amount: Tuple[List[InputSource], int, bool], outputAddresses: List[str], Comment: str = "", - OutputbackChange: str = None, + OutputbackChange: Optional[str] = None, ) -> Transaction: listinput = listinput_and_amount[0] diff --git a/silkaj/network.py b/silkaj/network.py index 433ec6f2..2fe1f15c 100644 --- a/silkaj/network.py +++ b/silkaj/network.py @@ -79,8 +79,9 @@ def send_document(bma_path: Any, document: Document) -> None: try: client(bma_path, document.signed_raw()) print(f"{doc_name} successfully sent") - except HTTPError as e: - sys.exit(f"Error while publishing {doc_name.lower()}: {e}") + except HTTPError as error: + print(error) + sys.exit(f"Error while publishing {doc_name.lower()}") def exit_on_http_error(error: HTTPError, err_code: int, message: str) -> None: @@ -90,4 +91,5 @@ def exit_on_http_error(error: HTTPError, err_code: int, message: str) -> None: """ if error.code == err_code: sys.exit(message) - sys.exit(error) + print(error) + sys.exit(constants.FAILURE_EXIT_STATUS) diff --git a/silkaj/tui.py b/silkaj/tui.py index 850a83e4..1578ea7d 100644 --- a/silkaj/tui.py +++ b/silkaj/tui.py @@ -16,7 +16,7 @@ import shutil import sys from collections import OrderedDict -from typing import Dict, List, Union +from typing import Dict, List, Optional, Union import click from texttable import Texttable @@ -42,7 +42,7 @@ class Table(Texttable): self.set_deco(self.HEADER | self.VLINES | self.BORDER) self.set_chars(VERT_TABLE_CHARS) - def fill_rows(self, rows: List[List], header: List = None) -> None: + def fill_rows(self, rows: List[List], header: Optional[List] = None) -> None: """ Fills a table from header and rows list. `rows` is a list of lists representing each row content. -- GitLab