Skip to content

Commit 6631803

Browse files
committed
Additional typing info
1 parent 53254ce commit 6631803

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

kytos/core/controller.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
from kytos.core.queue_monitor import QueueMonitorWindow
5353
from kytos.core.switch import Switch
5454

55+
import kytos.core.interface
56+
5557
__all__ = ('Controller',)
5658

5759

@@ -129,7 +131,7 @@ def __init__(self, options=None, loop: AbstractEventLoop = None):
129131
#: dict: Current existing switches.
130132
#:
131133
#: The key is the switch dpid, while the value is a Switch object.
132-
self.switches = {} # dpid: Switch()
134+
self.switches = dict[str, Switch]() # dpid: Switch()
133135
self._switches_lock = threading.Lock()
134136

135137
#: datetime.datetime: Time when the controller finished starting.
@@ -676,7 +678,10 @@ async def msg_out_event_handler(self):
676678
self.log.exception("Unhandled exception on msg_out",
677679
exc_info=exc)
678680

679-
def get_interface_by_id(self, interface_id):
681+
def get_interface_by_id(
682+
self,
683+
interface_id: str
684+
) -> "kytos.core.interface.Interface":
680685
"""Find a Interface with interface_id.
681686
682687
Args:

kytos/core/napps/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from kytos.core.events import KytosEvent
1515
from kytos.core.logs import NAppLog
1616

17+
import kytos.core.controller
18+
1719
__all__ = ('KytosNApp',)
1820

1921
LOG = NAppLog()
@@ -165,7 +167,7 @@ def _update_repo_file(self, destination=None):
165167
class KytosNApp(Thread, metaclass=ABCMeta):
166168
"""Base class for any KytosNApp to be developed."""
167169

168-
def __init__(self, controller, **kwargs):
170+
def __init__(self, controller: "kytos.core.controller.Controller", **kwargs):
169171
"""Contructor of KytosNapps.
170172
171173
Go through all of the instance methods and selects those that have

kytos/core/switch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, dpid, connection=None, features=None):
8080
#: (eth_type, mac_src, mac_dst) and the value is the timestamp of
8181
#: the last flood.
8282
self.flood_table = {}
83-
self.interfaces = {}
83+
self.interfaces = dict[int, Interface]()
8484
self.flows = []
8585
self.description = {}
8686
self._id = dpid

kytos/core/tag_ranges.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ def range_intersection(
150150
return intersections
151151

152152
def range_difference(
153-
ranges_a: list[Optional[list[int]]],
154-
ranges_b: list[Optional[list[int]]]
153+
ranges_a: list[list[int]],
154+
ranges_b: list[list[int]]
155155
) -> list[list[int]]:
156156
"""The operation is two validated list of ranges
157157
(ranges_a - ranges_b).
@@ -240,8 +240,8 @@ def range_difference(
240240

241241

242242
def range_addition(
243-
ranges_a: list[Optional[list[int]]],
244-
ranges_b: list[Optional[list[int]]]
243+
ranges_a: list[list[int]],
244+
ranges_b: list[list[int]]
245245
) -> tuple[list[list[int]], list[list[int]]]:
246246
"""Addition between two validated list of ranges.
247247
Simulates the addition between two sets.
@@ -280,28 +280,28 @@ def range_addition(
280280
merged_ranges = list[list[int]]()
281281
intersections = list[list[int]]()
282282

283-
top = ordered_ranges[0]
284-
285-
for tag_range in ordered_ranges[1:]:
286-
match top, tag_range:
287-
case [a_start, a_end], [b_start, b_end] if (
288-
a_end + 1 == b_start
289-
):
290-
top = [a_start, b_end]
291-
case [a_start, a_end], [b_start, b_end] if (
292-
b_start <= a_end and a_end <= b_end
293-
):
294-
top = [a_start, b_end]
295-
intersections.append([b_start, a_end])
296-
case [a_start, a_end], [b_start, b_end] if (
297-
b_end < a_end
298-
):
299-
intersections.append([b_start, b_end])
300-
case _, _:
301-
merged_ranges.append(top)
302-
top = tag_range
303-
304-
merged_ranges.append(top)
283+
if ordered_ranges:
284+
top = ordered_ranges[0]
285+
286+
for tag_range in ordered_ranges[1:]:
287+
match top, tag_range:
288+
case [a_start, a_end], [b_start, b_end] if (
289+
a_end + 1 == b_start
290+
):
291+
top = [a_start, b_end]
292+
case [a_start, a_end], [b_start, b_end] if (
293+
b_start <= a_end and a_end <= b_end
294+
):
295+
top = [a_start, b_end]
296+
intersections.append([b_start, a_end])
297+
case [a_start, a_end], [b_start, b_end] if (
298+
b_end < a_end
299+
):
300+
intersections.append([b_start, b_end])
301+
case _, _:
302+
merged_ranges.append(top)
303+
top = tag_range
304+
merged_ranges.append(top)
305305

306306
return (
307307
[

0 commit comments

Comments
 (0)