Skip to content
Snippets Groups Projects
Commit 06ded9b3 authored by Moul's avatar Moul
Browse files

[mypy] #163: identity_of(): always return a value

Move exception handling outside
parent 3f79a760
No related branches found
No related tags found
1 merge request!214#163: Introduce mypy
...@@ -17,6 +17,7 @@ from collections import OrderedDict ...@@ -17,6 +17,7 @@ from collections import OrderedDict
from operator import itemgetter from operator import itemgetter
from os import system from os import system
from typing import Dict, List, Tuple from typing import Dict, List, Tuple
from urllib.error import HTTPError
import jsonschema import jsonschema
from click import IntRange, argument, command, option from click import IntRange, argument, command, option
...@@ -151,14 +152,17 @@ def list_blocks(number: int, detailed: bool) -> None: ...@@ -151,14 +152,17 @@ def list_blocks(number: int, detailed: bool) -> None:
issuers.append(issuer) issuers.append(issuer)
for pubkey in issuers_dict.keys(): for pubkey in issuers_dict.keys():
issuer = issuers_dict[pubkey] issuer = issuers_dict[pubkey]
idty = identity_of(issuer["pubkey"]) try:
idty = identity_of(issuer["pubkey"])
except HTTPError:
idty = None
for issuer2 in issuers: for issuer2 in issuers:
if ( if (
issuer2.get("pubkey") is not None issuer2.get("pubkey") is not None
and issuer.get("pubkey") is not None and issuer.get("pubkey") is not None
and issuer2["pubkey"] == issuer["pubkey"] and issuer2["pubkey"] == issuer["pubkey"]
): ):
issuer2["uid"] = idty["uid"] issuer2["uid"] = idty["uid"] if idty else None
issuer2.pop("pubkey") issuer2.pop("pubkey")
header = ( header = (
f"Last {number} blocks from n°{current_nbr - number + 1} to n°{current_nbr}" f"Last {number} blocks from n°{current_nbr - number + 1} to n°{current_nbr}"
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. # along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
from typing import Dict, List, Optional from typing import Dict, List, Optional
from urllib.error import HTTPError
from duniterpy.api.bma import wot from duniterpy.api.bma import wot
...@@ -27,10 +28,7 @@ def identity_of(pubkey_uid: str) -> Dict: ...@@ -27,10 +28,7 @@ def identity_of(pubkey_uid: str) -> Dict:
Able to know if an identity is member or not Able to know if an identity is member or not
""" """
client = client_instance() client = client_instance()
try: return client(wot.identity_of, pubkey_uid)
return client(wot.identity_of, pubkey_uid)
except ValueError:
pass
def is_member(pubkey_uid: str) -> Optional[Dict]: def is_member(pubkey_uid: str) -> Optional[Dict]:
...@@ -40,7 +38,7 @@ def is_member(pubkey_uid: str) -> Optional[Dict]: ...@@ -40,7 +38,7 @@ def is_member(pubkey_uid: str) -> Optional[Dict]:
""" """
try: try:
return identity_of(pubkey_uid) return identity_of(pubkey_uid)
except Exception: except HTTPError:
return None return None
...@@ -67,6 +65,6 @@ def identities_from_pubkeys(pubkeys: List[str], uids: bool) -> List: ...@@ -67,6 +65,6 @@ def identities_from_pubkeys(pubkeys: List[str], uids: bool) -> List:
for pubkey in uniq_pubkeys: for pubkey in uniq_pubkeys:
try: try:
identities.append(identity_of(pubkey)) identities.append(identity_of(pubkey))
except Exception: except HTTPError:
pass pass
return identities return identities
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment