Commit 31d06c61 authored by Vincent Texier's avatar Vincent Texier

issue #52 add type hinting everywhere in the code (except on local variables)

parent 9abea36f
......@@ -18,6 +18,7 @@ Features
* Support HTTP, HTTPS and Web Socket transport for BMA API
* Support `Elasticsearch Duniter4j <https://git.duniter.org/clients/java/duniter4j/blob/master/src/site/markdown/ES.md#request-the-es-node>`_ API
* Duniter signing key
* Sign/verify and encrypt/decrypt messages with the Duniter credentials
Requirements
------------
......
......@@ -114,7 +114,7 @@ async def peering(client: Client) -> dict:
return await client.get(MODULE + '/peering', schema=PEERING_SCHEMA)
async def peers(client: Client, leaves: bool = False, leaf: str = ""):
async def peers(client: Client, leaves: bool = False, leaf: str = "") -> dict:
"""
GET peering entries of every node inside the currency network
......
......@@ -16,6 +16,7 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
# vit
import logging
from duniterpy.api.client import Client
logger = logging.getLogger("duniter/node")
......
......@@ -222,7 +222,7 @@ async def process(client: Client, transaction_signed_raw: str) -> ClientResponse
return await client.post(MODULE + '/process', {'transaction': transaction_signed_raw}, rtype=RESPONSE_AIOHTTP)
async def sources(client: Client, pubkey: str):
async def sources(client: Client, pubkey: str) -> dict:
"""
GET transaction sources
......
......@@ -16,6 +16,7 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
# vit
import logging
from duniterpy.api.client import Client
logger = logging.getLogger("duniter/ud")
......@@ -74,4 +75,3 @@ async def history(client: Client, pubkey: str) -> dict:
:rtype: dict
"""
return await client.get(MODULE + '/history/%s' % pubkey, schema=UD_SCHEMA)
......@@ -18,6 +18,8 @@
# vit
import logging
from aiohttp import ClientWebSocketResponse
from duniterpy.api.bma.blockchain import BLOCK_SCHEMA
from duniterpy.api.client import Client
......@@ -53,21 +55,21 @@ WS_PEER_SCHEMA = {
}
def block(client: Client):
def block(client: Client) -> ClientWebSocketResponse:
"""
Connect to block websocket
:param client: Client to connect to the api
:rtype: aiohttp.ClientWebSocketResponse
:rtype: ClientWebSocketResponse
"""
return client.connect_ws(MODULE + '/block')
def peer(client: Client):
def peer(client: Client) -> ClientWebSocketResponse:
"""
Connect to peer websocket
:param client: Client to connect to the api
:rtype: aiohttp.ClientWebSocketResponse
:rtype: ClientWebSocketResponse
"""
return client.connect_ws(MODULE + '/peer')
......@@ -6,8 +6,8 @@ import json
import logging
from typing import Callable, Union, Any, Optional
import aiohttp
import jsonschema
from aiohttp import ClientResponse, ClientWebSocketResponse, ClientSession
import duniterpy.api.endpoint as endpoint
from .errors import DuniterError
......@@ -67,7 +67,7 @@ def parse_error(text: str) -> Any:
return data
async def parse_response(response: aiohttp.ClientResponse, schema: dict) -> Any:
async def parse_response(response: ClientResponse, schema: dict) -> Any:
"""
Validate and parse the BMA answer
......@@ -124,12 +124,12 @@ class API(object):
return url + path
async def requests_get(self, path: str, **kwargs) -> aiohttp.ClientResponse:
async def requests_get(self, path: str, **kwargs) -> ClientResponse:
"""
Requests GET wrapper in order to use API parameters.
:param path: the request path
:rtype: aiohttp.ClientResponse
:rtype: ClientResponse
"""
logging.debug("Request : {0}".format(self.reverse_url(self.connection_handler.http_scheme, path)))
url = self.reverse_url(self.connection_handler.http_scheme, path)
......@@ -145,12 +145,12 @@ class API(object):
return response
async def requests_post(self, path: str, **kwargs) -> aiohttp.ClientResponse:
async def requests_post(self, path: str, **kwargs) -> ClientResponse:
"""
Requests POST wrapper in order to use API parameters.
:param path: the request path
:rtype: aiohttp.ClientResponse
:rtype: ClientResponse
"""
if 'self_' in kwargs:
kwargs['self'] = kwargs.pop('self_')
......@@ -165,7 +165,7 @@ class API(object):
)
return response
def connect_ws(self, path: str) -> aiohttp.ClientWebSocketResponse:
def connect_ws(self, path: str) -> ClientWebSocketResponse:
"""
Connect to a websocket in order to use API parameters
......@@ -175,7 +175,7 @@ class API(object):
and close the ClientWebSocketResponse in it.
:param path: the url path
:rtype: aiohttp.ClientWebSocketResponse
:rtype: ClientWebSocketResponse
"""
url = self.reverse_url(self.connection_handler.ws_scheme, path)
return self.connection_handler.session.ws_connect(url, proxy=self.connection_handler.proxy)
......@@ -186,7 +186,7 @@ class Client:
Main class to create an API client
"""
def __init__(self, _endpoint: Union[str, endpoint.Endpoint], session: aiohttp.ClientSession = None,
def __init__(self, _endpoint: Union[str, endpoint.Endpoint], session: ClientSession = None,
proxy: str = None) -> None:
"""
Init Client instance
......@@ -207,7 +207,7 @@ class Client:
# if no user session...
if session is None:
# open a session
self.session = aiohttp.ClientSession()
self.session = ClientSession()
else:
self.session = session
self.proxy = proxy
......@@ -274,12 +274,12 @@ class Client:
elif rtype == RESPONSE_JSON:
return await response.json()
def connect_ws(self, path: str) -> aiohttp.ClientWebSocketResponse:
def connect_ws(self, path: str) -> ClientWebSocketResponse:
"""
Connect to a websocket in order to use API parameters
:param path: the url path
:rtype: aiohttp.ClientWebSocketResponse
:rtype: ClientWebSocketResponse
"""
client = API(self.endpoint.conn_handler(self.session, self.proxy))
return client.connect_ws(path)
......
This diff is collapsed.
......@@ -55,6 +55,7 @@ WS2P_HEADS_SCHEMA = {
}
# fixme: ws2p heads support must be handled by websocket
def heads(client: Client):
"""
GET Certification data over a member
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment