From 5fef54849b3e73ffa484c920af477d95c9cf31c6 Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Sun, 5 Mar 2023 18:40:02 +0100
Subject: [PATCH] Introduce Pylint rules and fix pylint reports

---
 pyproject.toml                        |  3 ++-
 silkaj/checksum.py                    | 23 +++++++++++------------
 silkaj/money/transfer.py              |  2 +-
 silkaj/tools.py                       |  2 +-
 silkaj/wot/tools.py                   |  5 ++---
 tests/unit/money/test_transfer_cli.py |  2 +-
 tests/unit/test_public_key.py         |  2 +-
 7 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 0cefdc06..eac5e958 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -48,5 +48,6 @@ ignore_missing_imports = true
 line-length = 101
 target-version = "py37"
 select = ["W", "I", "UP", "YTT", "B", "A", "DTZ", "T10",
-"EXE", "ISC", "ICN", "G", "INP", "PIE", "PYI", "Q", "RSE", "SLF", "TID",
+"EXE", "ISC", "ICN", "G", "INP", "PIE", "PYI", "Q", "RSE", "SLF", "TID", "PL",
 "COM", "C4", "PT", "RET", "SIM", "PTH", "PGH", "PL", "TRY", "RUF"]
+ignore = ["PLR2004", "PLR0913"]
diff --git a/silkaj/checksum.py b/silkaj/checksum.py
index beb173c2..0e81d111 100644
--- a/silkaj/checksum.py
+++ b/silkaj/checksum.py
@@ -39,16 +39,15 @@ def checksum_command(pubkey_checksum: str) -> None:
     if has_auth_method():
         key = auth_method()
         click.echo(gen_pubkey_checksum(key.pubkey))
-    else:
-        if not pubkey_checksum:
-            sys.exit(MESSAGE)
-        elif re.search(re.compile(PUBKEY_DELIMITED_PATTERN), pubkey_checksum[0]):
-            click.echo(gen_pubkey_checksum(pubkey_checksum[0]))
-        elif re.search(re.compile(PUBKEY_CHECKSUM_PATTERN), pubkey_checksum[0]):
-            pubkey, checksum = pubkey_checksum[0].split(":")
-            if checksum == gen_checksum(pubkey):
-                click.echo("The checksum is valid")
-            else:
-                click.echo("The checksum is invalid")
+    elif not pubkey_checksum:
+        sys.exit(MESSAGE)
+    elif re.search(re.compile(PUBKEY_DELIMITED_PATTERN), pubkey_checksum[0]):
+        click.echo(gen_pubkey_checksum(pubkey_checksum[0]))
+    elif re.search(re.compile(PUBKEY_CHECKSUM_PATTERN), pubkey_checksum[0]):
+        pubkey, checksum = pubkey_checksum[0].split(":")
+        if checksum == gen_checksum(pubkey):
+            click.echo("The checksum is valid")
         else:
-            sys.exit("Error: Wrong public key format")
+            click.echo("The checksum is invalid")
+    else:
+        sys.exit("Error: Wrong public key format")
diff --git a/silkaj/money/transfer.py b/silkaj/money/transfer.py
index ca821d3b..99473f92 100644
--- a/silkaj/money/transfer.py
+++ b/silkaj/money/transfer.py
@@ -265,7 +265,7 @@ def transaction_amount(
     # In case one amount is passed with multiple recipients
     # generate list containing multiple time the same amount
     if len(amounts_list) == 1 and len(outputAddresses) > 1:
-        amounts_list = [amounts_list[0]] * len(outputAddresses)
+        return [amounts_list[0]] * len(outputAddresses)
     return amounts_list
 
 
diff --git a/silkaj/tools.py b/silkaj/tools.py
index 88c51e61..1ef2a719 100644
--- a/silkaj/tools.py
+++ b/silkaj/tools.py
@@ -52,7 +52,7 @@ class MutuallyExclusiveOption(click.Option):
         if self.mutually_exclusive.intersection(opts) and self.name in opts:
             arguments = ", ".join(self.mutually_exclusive)
             raise click.UsageError(
-                f"Usage: `{self.name}` is mutually exclusive with arguments `{arguments}`.",
+                message=f"Usage: `{self.name}` is mutually exclusive with arguments `{arguments}`.",
             )
 
         return super().handle_parse_result(ctx, opts, args)
diff --git a/silkaj/wot/tools.py b/silkaj/wot/tools.py
index 1899f0d6..ce36406a 100644
--- a/silkaj/wot/tools.py
+++ b/silkaj/wot/tools.py
@@ -13,6 +13,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
 
+import contextlib
 import time
 import urllib
 from typing import Dict, List, Optional, Tuple
@@ -70,10 +71,8 @@ def identities_from_pubkeys(pubkeys: List[str], uids: bool) -> List:
     identities = []
     for pubkey in uniq_pubkeys:
         time.sleep(BMA_SLEEP)
-        try:
+        with contextlib.suppress(HTTPError):
             identities.append(identity_of(pubkey))
-        except HTTPError:
-            pass
     return identities
 
 
diff --git a/tests/unit/money/test_transfer_cli.py b/tests/unit/money/test_transfer_cli.py
index 780a7b7c..021a14c6 100644
--- a/tests/unit/money/test_transfer_cli.py
+++ b/tests/unit/money/test_transfer_cli.py
@@ -118,7 +118,7 @@ def test_transaction_amount_errors(
     monkeypatch.setattr(m_tools, "get_ud_value", patched_get_ud_value)
 
     # check program exit on error
-    with pytest.raises(SystemExit) as pytest_exit:
+    with pytest.raises(SystemExit) as pytest_exit:  # noqa: PT012
         # read output to check error.
         transfer.transaction_amount(amounts, UDs_amounts, outputAddresses)
         assert expected == capsys.readouterr()
diff --git a/tests/unit/test_public_key.py b/tests/unit/test_public_key.py
index 0dfeb236..0aa117a6 100644
--- a/tests/unit/test_public_key.py
+++ b/tests/unit/test_public_key.py
@@ -110,7 +110,7 @@ J4c8CARmP9vAFNGtHRuzx14zvxojyRWHW2darguVqjtX",
     ],
 )
 def test_is_pubkey_and_check_errors(uid_pubkey, expected, capsys):
-    with pytest.raises(SystemExit) as pytest_exit:
+    with pytest.raises(SystemExit) as pytest_exit:  # noqa: PT012
         public_key.is_pubkey_and_check(uid_pubkey)
         assert capsys.readouterr() == expected
     assert pytest_exit.type == SystemExit
-- 
GitLab