Skip to content

Explicit List of Tuple do not support __setitem__ with index #1578

Closed
@tharvik

Description

@tharvik
from typing import List, Tuple

l = []  # type: List[Tuple[int, int]]
l.append((1, 2))

l[0] = 3, 4
l[:] = [(5, 6)]

gives

asd.py:6: error: No overload variant of "__setitem__" of "list" matches argument types [builtins.int, Tuple[builtins.int, builtins.int]]

so __setitem__ with slice works but not with index.

Not specifing the type does work (it is just an example, the code I'm working on need to explicit a specific variable).

I don't think it is an issue in typeshed as playing with builtins.list do not change a thing.
btw, simply exchanging the @overload __setitem__ gives me weirder errors, like

asd.py:1: note: In module imported here:
/home/tharvik/mypy/typeshed/stdlib/3/builtins.pyi: note: In class "list":
/home/tharvik/mypy/typeshed/stdlib/3/builtins.pyi:477: error: Signature of "__setitem__" incompatible with supertype "MutableSequence"
asd.py: note: At top level:
asd.py:6: error: No overload variant of "__setitem__" of "list" matches argument types [builtins.int, Tuple[builtins.int, builtins.int]]

The order shouldn't matter, right? (I didn't see it written in the PEP anyway)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions