From 69b657d7b62d82c210dee8b9bdf5b294ce035fd9 Mon Sep 17 00:00:00 2001 From: KV Date: Sun, 6 Sep 2020 21:46:29 +0200 Subject: [PATCH] Add type annotation of methods too --- src/wireviz/DataClasses.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 8db564df..3571ffb4 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -37,7 +37,7 @@ class Connector: autogenerate: bool = False loops: List[List[Pin]] = field(default_factory=list) - def __post_init__(self): + def __post_init__(self) -> None: self.ports_left = False self.ports_right = False self.visible_pins = {} @@ -81,7 +81,7 @@ def __post_init__(self): if len(loop) != 2: raise Exception('Loops must be between exactly two pins!') - def activate_pin(self, pin): + def activate_pin(self, pin: Pin) -> None: self.visible_pins[pin] = True @@ -106,7 +106,7 @@ class Cable: show_name: bool = True show_wirecount: bool = True - def __post_init__(self): + def __post_init__(self) -> None: if isinstance(self.gauge, str): # gauge and unit specified try: @@ -160,7 +160,10 @@ def __post_init__(self): raise Exception('lists of part data are only supported for bundles') - def connect(self, from_name, from_pin, via_pin, to_name, to_pin): + # Pins = Union[Pin, Tuple[Pin, ...], None] # None, one, or a tuple of pins + # Wires = Union[Wire, Tuple[Wire, ...]] # One or a tuple of wires + # The *_pin arguments also accept a tuple, but it seems not in use with the current code. + def connect(self, from_name: Optional[Name], from_pin: Optional[Pin], via_pin: Wire, to_name: Optional[Name], to_pin: Optional[Pin]) -> None: from_pin = int2tuple(from_pin) via_pin = int2tuple(via_pin) to_pin = int2tuple(to_pin)