Skip to content

Wrong type inference for <tuple>[s] where s: slice #21708

Description

@bzoracler

Bug Report

a = (1, 2, 3)
s = slice(None, 1)
reveal_type(a[s])  # Revealed type is `builtins.int`
reveal_type(a.__getitem__(s))  # Revealed type is `builtins.tuple[builtins.int, ...]` (OK)

The runtime value of a[s] is (1,).

The type inference works for lists though.

Your Environment

  • Mypy version used: 1.0.0-2.1, master
  • Python version used: 3.12, 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions