Python API tuplelist type hinting
AnsweredDear Gurobi,
I'm a big fan of the Python API. I especially like the tuplelist, that I use a lot to create the indices for the variables and constraints. I use PyCharm when coding in Python and I don't know if the following is specific to PyCharm, but when iterating over the elements in a tuplelist, I don't get any type hinting as when iterating over elements in a normal list:
As you can see in the picture, PyCharm has no knowledge of the types of the elements in the typelist. To handle this I have implemented a wrapper class that enherits from tuplelist and Generic, so I can get type hinting as you can see in the following images:
I find this very helpful when I create constraints and the elements are custom classes and I want to make some if statements, that needs to check for certain conditions on the object.
My question is: would it be possible to add something similar to your API, so other developers could benefit from it as well?
-
Great idea Niels-Christian Bagger
I always have to go back to where I initialized the list to remember which order I used for the indices when creating the TupleList.0 -
Hi Niels-Christian and Michael,
We recently released the gurobipy-stubs package that provides type hinting for gurobipy. You can install it in your python environment through pip.
We hope you will consider using these stubs. Please let us know if you encounter any issues.
Best regards,
Maliheh
0 -
Thank you for that. I will definitely take a look at this
0
Please sign in to leave a comment.
Comments
3 comments