Type Annotation
Is there any work being done to support type annotation for this library?
Hi @iwoloschin , We support type hinting in the latest version of our library. As our library is for both python 2 and 3 versions, we define type hinting as comments. Please see the below example. If we see the vport.py from our library
@property
def Location(self):
# type: () -> str
"""
Returns
-------
- str: The current format is {chassisIp}/{frontPanelPort}.{fanoutPort} or {chassisIp};{cardId};{portId} for legacy systems.
"""
return self._get_attribute(self._SDM_ATT_MAP['Location'])
@Location.setter
def Location(self, value):
# type: (str) -> None
self._set_attribute(self._SDM_ATT_MAP['Location'], value)
Please let us know if this answers your question. If not, please let us know what exactly are you looking for.
It looks like a lot of things, particularly @property getters, do not have return types properly assigned. If we could get these properly annotated it would make using this library in editors that support python type annotations, like VS Code with Pylance, a lot easier. For example, consider these two lines:
from ixnetwork_restpy import SessionAssistant
session = SessionAssistant()
session.Ixnetwork.Traffic
According to Pylance the Traffic object is Unknown | Self@Base. As far as I can tell this is technically correct based on Pylance's inference, but not very helpful for someone trying to get to an attribute of Traffic.
Separately, it may also be helpful to organize common types in an easily accessible location for applications to import to use themselves, for example if I wanted to pass Traffic to a function, I need to do this:
from ixnetwork_restpy.testplatform.sessions.ixnetwork.traffic.traffic import Traffic
def do_traffic(traffic: Traffic) -> None:
It gets worse with TrafficItem!
from ixnetwork_restpy.testplatform.sessions.ixnetwork.traffic.trafficitem.trafficitem import TrafficItem
def do_traffic_item(traffic_item: TrafficItem) -> None:
Python type annotations are obviously never necessary, but they can make a huge difference in how fast & comfortable it is to use a complex library such as this one.