Skip to content

Commit 466c369

Browse files
committed
Add more type hints.
1 parent cb3810f commit 466c369

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

openlcb/node.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from enum import Enum
1717
from typing import Set
18+
from openlcb.nodeid import NodeID
1819
from openlcb.pip import PIP
1920
from openlcb.snip import SNIP
2021
from openlcb.localeventstore import LocalEventStore
@@ -40,11 +41,12 @@ class Node:
4041
events (LocalEventStore): The store for local events associated
4142
with the node.
4243
"""
43-
def __init__(self, nodeID, snip: SNIP = None, pipSet: Set[PIP] = None):
44-
self.id = nodeID
45-
self.snip = snip
44+
def __init__(self, nodeID: NodeID, snip: SNIP = None,
45+
pipSet: Set[PIP] = None):
46+
self.id: NodeID = nodeID
47+
self.snip: SNIP = snip
4648
if snip is None : self.snip = SNIP()
47-
self.pipSet = pipSet
49+
self.pipSet: Set[PIP] = pipSet
4850
if pipSet is None : self.pipSet = set([])
4951
self.state = Node.State.Uninitialized
5052
self.events = LocalEventStore()

openlcb/nodestore.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import (
2+
Dict,
23
List, # in case list doesn't support `[` in this Python version
34
Union, # in case `|` doesn't support 'type' in this Python version
45
)
@@ -18,7 +19,7 @@ class NodeStore :
1819
'''
1920

2021
def __init__(self) :
21-
self.byIdMap: dict = {}
22+
self.byIdMap: Dict[NodeID, Node] = {}
2223
self.nodes: List[Node] = []
2324
self.processors: List[Processor] = []
2425

@@ -34,10 +35,10 @@ def store(self, node: Node) :
3435
self.nodes.sort(key=lambda x: x.snip.userProvidedNodeName,
3536
reverse=True)
3637

37-
def isPresent(self, nodeID) :
38+
def isPresent(self, nodeID: NodeID) -> bool:
3839
return self.byIdMap.get(nodeID) is not None
3940

40-
def asArray(self) :
41+
def asArray(self) -> List[Node]:
4142
return [self.byIdMap[i] for i in self.byIdMap]
4243

4344
# Retrieve a Node's content from the store

0 commit comments

Comments
 (0)