linopy icon indicating copy to clipboard operation
linopy copied to clipboard

mypy claims Variable +/* DataArray not supported

Open apfelix opened this issue 7 months ago • 0 comments

Version Checks (indicate both or one)

  • [x] I have confirmed this bug exists on the lastest release of Linopy.

  • [ ] I have confirmed this bug exists on the current master branch of Linopy.

Issue Description

Hi,

as far as I know Linopy supports type checking via mypy. However, when I add/multiply a linopy.Variable with a xarray.DataArray I get a Unsupported operand types for <...> ("Variable" and "DataArray") error from mypy. Executing the code works as expected.

Tested with latest versions of all 3 packages: linopy-0.5.2 mypy-1.15.0 xarray-2025.3.0

Reproducible Example

import linopy
import xarray as xr

m = linopy.Model()

a: xr.DataArray = xr.DataArray([1, 2, 3])
v: linopy.Variable = m.add_variables(lower=a, name="v")

# this gives
# > error: Unsupported operand types for * ("Variable" and "DataArray")  [operator]
m.add_constraints(v * a * 10.0 <= 0.0)
# > error: Unsupported operand types for + ("Variable" and "DataArray")  [operator]
m.add_constraints(v + a * 10.0 <= 0.0)

Expected Behavior

No mypy error, as the code works as expected.

Installed Versions

linopy-0.5.2 mypy-1.15.0 xarray-2025.3.0

apfelix avatar Mar 25 '25 07:03 apfelix