From 9349af1935b2addfc0727082f169329fff4dcb2d Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sun, 5 Jun 2022 16:42:48 +0200 Subject: [PATCH] [mypy] #163: Add type annotation on network_tools --- silkaj/network_tools.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/silkaj/network_tools.py b/silkaj/network_tools.py index 3d34442a..13c2f074 100644 --- a/silkaj/network_tools.py +++ b/silkaj/network_tools.py @@ -16,16 +16,18 @@ import functools import re import sys -import urllib +from typing import Any +from urllib.error import HTTPError from duniterpy import constants as du_const from duniterpy.api import endpoint as ep from duniterpy.api.client import Client +from duniterpy.documents import Document from silkaj import constants -def determine_endpoint(): +def determine_endpoint() -> ep.Endpoint: """ Pass custom endpoint, parse through a regex {host|ipv4|[ipv6]}:{port}{/path} @@ -73,17 +75,17 @@ def client_instance(): return Client(determine_endpoint()) -def send_document(bma_path, document): +def send_document(bma_path: Any, document: Document) -> None: client = client_instance() doc_name = document.__class__.__name__ try: client(bma_path, document.signed_raw()) print(f"{doc_name} successfully sent") - except urllib.error.HTTPError as e: + except HTTPError as e: sys.exit(f"Error while publishing {doc_name.lower()}: {e}") -def exit_on_http_error(error: urllib.error.HTTPError, err_code: int, message: str): +def exit_on_http_error(error: HTTPError, err_code: int, message: str) -> None: """ Nicely displays a message on an expected error code. Else, displays the HTTP error message. -- GitLab