Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Annotation #62

Open
iwoloschin opened this issue Feb 2, 2022 · 2 comments
Open

Type Annotation #62

iwoloschin opened this issue Feb 2, 2022 · 2 comments

Comments

@iwoloschin
Copy link

Is there any work being done to support type annotation for this library?

@Vibaswan
Copy link
Collaborator

Vibaswan commented Feb 4, 2022

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.

@iwoloschin
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants