Skip to content

bug: mypy error in merge() — type assignment mismatch #652

Description

@FBumann

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:

defmerge(
...
cls: type[GenericExpression] =None, # type: ignore
...
):
...
ifclsisNone:
cls=QuadraticExpressionifhas_quad_expressionelseLinearExpression# error

Environment

  • linopy: master (36bc106)
  • mypy: 1.20.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions