Git Product home page Git Product logo

gurobipy-stubs's Introduction

gurobipy-stubs

This package is no longer maintained. gurobipy versions 11.0 and later will include type hints as part of the installation, so the stubs are no longer needed.

This package provides type hints for gurobipy, the Python API for Gurobi. These stubs help you to write typed Python code, and enhance many IDE's built-in auto completion features.

Version Compatibility

  • Version 1.0 of this package provides type hints for gurobipy 9.x.
  • Version 2.0 of this package provides type hints for gurobipy 10.x.
  • For later versions of gurobipy, you should not install this package.

Example

With this type stubs package installed, static type checkers such as mypy will be able to verify the types given in source code annotations like in this example:

import gurobipy as gp

m: gp.Model = gp.Model()
v: gp.Var = m.addVar()
m.optimize()
vval: float = v.X
% mypy example.py 
Success: no issues found in 1 source file

gurobipy-stubs's People

Contributors

dr-irv avatar etowle avatar pobonomo avatar rluce avatar simonbowly avatar tobiasachterberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gurobipy-stubs's Issues

Add stubs for gp.Env environment variables like ClientEnv, CloudEnv

In my project, mypy was complaining at the following code:

import gurobipy as gp

env = gp.Env.ClientEnv(
        logfilename="", computeServer="my_gurobi_server", password="my_password"
    )

Raising the following error: "Type[Env]" has no attribute "ClientEnv" [attr-defined]mypy(error)

And when investigating, I realized that the stubs for Env indeed do not include any attributes, only methods. It would be nice to modify the stubs to avoid needing to use type:ignore

Discrepancy between NumPy's ShapeLike and ours

I think NumPy's ShapeLike is this:

from typing import Sequence, Tuple, Union, SupportsIndex

_Shape = Tuple[int, ...]

# Anything that can be coerced to a shape tuple
_ShapeLike = Union[SupportsIndex, Sequence[SupportsIndex]]

Is our ShapeLike truly a subset of theirs? Would our use of ShapeLike actually allow their definition? We don't need to adapt to that kind of detail, but we should be aware of the consequences.

Excessive usage of type "Any".

In the new version of gurobipy stubs, some functions start to return "Any" instead of _Scalar (for instance, getParamsInfo).
The main problem with "Any" is the following: "Any" means ignore type.
According to the "Åny" type documentation:
"Notice that no type checking is performed when assigning a value of type Any to a more precise type."
So, "Any" is the same as the absence of type but only looks nicer.
If you need to use a supertype of every type, it is better to use "object" instead of "Any"

Postfix releases to prevent installation on gurobi > 10

Not sure what the usual practice is here. Installing the stubs will overwrite the type hints included with future gurobipy installs so we should try to prevent installing the stubs or at least warn the user.

gurobipy dependency version of the current packages on PyPI:

  • gurobipy-stubs 1.0.x depends on gurobipy>=9.5.0 (we may want to post-fix these versions? or publish a 1.0.2 and yank the others so the user at least gets a loud warning)
  • gurobipy-stubs 2.0.0 depends on gurobipy==10.* (nothing to do for this one, and no need to update setup.py on the master branch)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.