Skip to content

Incorrect error [list-tem] with deque #19156

Duplicate of#10588
@snovik75

Description

@snovik75

Bug Report

Error [list-item] is incorrectly raised. I tried various ways but none of them succeeded to convince mype

To Reproduce

from collections import deque

_table: str = "smth"
_columns: list[str] | None = None

queue: deque[tuple[str, str | None]] = deque(
    (_table, c) for c in _columns or [None]
)

Expected Behavior

No error

Actual Behavior

mypy.py:7: error: List item 0 has incompatible type
"None"; expected "str" [list-item]
(_table, c) for c in (_columns or [None])

Your Environment

  • linux ubuntu

  • Mypy version used: 1.15

  • Mypy command-line flags: None

  • Mypy configuration options from mypy.ini (and other config files):
    # mypy
    [tool.mypy]
    python_version = 3.12
    pretty = true
    strict = true
    ignore_missing_imports = true
    warn_redundant_casts = true
    warn_unused_ignores = true
    check_untyped_defs = true # Type-checks the interior of functions without type annotations.
    disable_error_code = ["no-untyped-call", "type-arg", "no-untyped-def", "union-attr"]

        [[tool.mypy.overrides]]
        module = "tests.*"
        ignore_errors = true
    
  • Python version used: 3.12

Activity

sterliakov

sterliakov commented on May 28, 2025

@sterliakov
Collaborator

Deque is a red herring here, the following reproduces the same issue:

def foo(columns: list[str] | None) -> None:
    bad: list[str] | list[None] = columns or [None]  # E: List item 0 has incompatible type "None"; expected "str"  [list-item]
    good: list[str] | list[None] = [None] or columns or []
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

    bugmypy got something wrongtopic-type-contextType context / bidirectional inference

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @snovik75@sterliakov

        Issue actions

          Incorrect error [list-tem] with deque · Issue #19156 · python/mypy