Description
mypy reports an error on master at expressions.py:2387:
linopy/expressions.py:2387: error: Incompatible types in assignment
(expression has type "type[QuadraticExpression] | type[LinearExpression]",
variable has type "type[GenericExpression]") [assignment]
The cls parameter of merge() is typed as type[GenericExpression], but when cls is None, it gets reassigned to either QuadraticExpression or LinearExpression — both concrete subclasses, which mypy considers incompatible with the declared type.
Location
linopy/expressions.py:2343-2387:
def merge(
...
cls: type[GenericExpression] = None, # type: ignore
...
):
...
if cls is None:
cls = QuadraticExpression if has_quad_expression else LinearExpression # error
Environment
- linopy: master (36bc106)
- mypy: 1.20.1
Description
mypy reports an error on master at
expressions.py:2387:The
clsparameter ofmerge()is typed astype[GenericExpression], but whencls is None, it gets reassigned to eitherQuadraticExpressionorLinearExpression— both concrete subclasses, which mypy considers incompatible with the declared type.Location
linopy/expressions.py:2343-2387:Environment