Skip to content

Definition of "__iter__" in "ItemsView" is incompatible with definition "Sequence" #5973

@althonos

Description

@althonos

Hi there !

Trying to annotate a class inheriting from both a sequence and an items view will raise an error, although I believe both definitions are compatible in the following case:

from typing import *

K = TypeVar('K')
V = TypeVar('V')

class OrderedItemsView(Generic[K, V], ItemsView[K, V], Sequence[Tuple[K, V]]):
  def __iter__(self) -> Iterator[Tuple[K, V]]:
    return iter([])

This example raises:

test.py:7: error: Definition of "__iter__" in base class "ItemsView" is incompatible with definition in base class "Sequence"

although, for the two base classes, I believe __iter__ to be defined as Iterator[Tuple[K, V]].

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions