Skip to content

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

@FBumann

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:

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

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