From 6e50a6249f4af0d7ce11b16e40bf5c9c1c5c1fe0 Mon Sep 17 00:00:00 2001 From: Vincent Texier <vit@free.fr> Date: Sat, 14 Mar 2015 11:36:23 +0100 Subject: [PATCH] Add docstrings and type on properties and params --- src/cutecoin/core/net/node.py | 23 +++++++++++++++++------ src/cutecoin/models/network.py | 9 +++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index 3c7ef40a..60cb7235 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -16,9 +16,9 @@ from PyQt5.QtCore import QObject, pyqtSignal class Node(QObject): - ''' + """ classdocs - ''' + """ ONLINE = 1 OFFLINE = 2 @@ -27,10 +27,17 @@ class Node(QObject): changed = pyqtSignal() - def __init__(self, currency, endpoints, pubkey, block, state): - ''' + def __init__(self, currency: str, endpoints: list, pubkey: str, block: int, state: int): + """ Constructor - ''' + :param str currency: Name of the currency + :param list endpoints: List of BMAEndpoint + :param str pubkey: Public key of the node owner + :param int block: Last block number + :param int state: State of the node + :return: + """ + super().__init__() self._endpoints = endpoints self._pubkey = pubkey @@ -91,7 +98,7 @@ class Node(QObject): return self._pubkey @property - def endpoint(self): + def endpoint(self) -> BMAEndpoint: return next((e for e in self._endpoints if type(e) is BMAEndpoint)) @property @@ -193,3 +200,7 @@ class Node(QObject): time.sleep(interval) except RequestException as e: self._state = Node.OFFLINE + + def __str__(self): + return ','.join([str(self.pubkey), str(self.endpoint.server), str(self.endpoint.port), str(self.block), + str(self.currency), str(self.state), str(self.neighbours)]) diff --git a/src/cutecoin/models/network.py b/src/cutecoin/models/network.py index 946d1302..63d725fa 100644 --- a/src/cutecoin/models/network.py +++ b/src/cutecoin/models/network.py @@ -94,7 +94,12 @@ class NetworkTableModel(QAbstractTableModel): return self.column_types[section] - def data_node(self, node): + def data_node(self, node: Node) -> tuple: + """ + Return node data tuple + :param ..core.net.node.Node node: Network node + :return: + """ try: person = Person.lookup(node.pubkey, self.community) uid = person.name @@ -112,7 +117,7 @@ class NetworkTableModel(QAbstractTableModel): address = node.endpoint.ipv6 port = node.endpoint.port - return (node.pubkey, is_member, uid, address, port, node.block) + return node.pubkey, is_member, uid, address, port, node.block def data(self, index, role): row = index.row() -- GitLab