Skip to content

Commit

Permalink
Make type definitions in node.clone plugin compatible with Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ipspace committed Dec 24, 2024
1 parent 4c31a0f commit 379026a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions netsim/extra/node.clone/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing

from box import Box
from netsim import data
from netsim.utils import log,strings
Expand All @@ -6,7 +8,7 @@
"""
clone_link - makes a copy of the given link for each clone, updating its node
"""
def clone_link(link_data: Box, nodename: str, clones: list[str]) -> list[Box]:
def clone_link(link_data: Box, nodename: str, clones: typing.List[str]) -> typing.List[Box]:
cloned_links = []
if nodename in [ i.node for i in link_data.get('interfaces',[]) ]:
for c,clone in enumerate(clones):
Expand All @@ -25,7 +27,13 @@ def clone_link(link_data: Box, nodename: str, clones: list[str]) -> list[Box]:
"""
clone_lag - special routine to handle cloning of lag links
"""
def clone_lag(cnt: int, link_data: Box, nodename: str, clones: list[str], topology: Box) -> list[Box]:
def clone_lag(
cnt: int,
link_data: Box,
nodename: str,
clones: typing.List[str],
topology: Box) -> typing.List[Box]:

lag_members = link_data.get('lag.members')
cloned_members = process_links(lag_members,f"lag[{cnt+1}].m",nodename,clones,topology)
if not cloned_members: # If no lag members involve <nodename>
Expand All @@ -51,8 +59,13 @@ def clone_lag(cnt: int, link_data: Box, nodename: str, clones: list[str], topolo
Returns a list of a list of cloned links
"""
def process_links(linkitems: list, linkprefix: str, nodename: str, clones: list, topology: Box) -> list[list[Box]]:
result: list[list[Box]] = []
def process_links(
linkitems: list,
linkprefix: str,
nodename: str, clones: list,
topology: Box) -> typing.List[typing.List[Box]]:

result: typing.List[typing.List[Box]] = []
for cnt,l in enumerate(list(linkitems)):
link_data = links.adjust_link_object( # Create link data from link definition
l=l,
Expand Down

2 comments on commit 379026a

@jbemmel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some list entries remaining, e.g.

@ipspace
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the "list" type, but cannot specify the type of the items. For that, you need typing.List[itemtype]

Please sign in to comment.