Skip to content

mypy throws assignment error for a list created from an empty list #18735

Open
@Felixoid

Description

@Felixoid

Bug Report

mypy fails to proceed sorting of the empty list, considering it's a list[object], see the reproduce script and the output

To Reproduce

a: list[str] | list[int] = []
a = sorted(a)

Expected Behavior

There shouldn't be errors

Actual Behavior

> mypy .
/tmp/test.py:2: error: Incompatible types in assignment (expression has type "list[SupportsDunderLT[Any] | SupportsDunderGT[Any]]", variable has type "list[str] | list[int]")  [assignment]

Your Environment

  • Mypy version used: mypy 1.14.0 (compiled: no)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.13.2

In the scope of ClickHouse/ClickHouse#76679

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions