This question has already been discussed in #18 long time ago, but now I stumble on this in a practical question: How to annotate something that subclasses two ABC's. Currently, a workaround is to introduce a "mix" class:
fromtypingimportIterable, ContainerclassIterableContainer(Iterable[int], Container[int]):
...
deff(x: IterableContainer) ->None: ...
classTest(IterableContainer):
def__iter__(self): ...
def__contains__(self, item: int) ->bool: ...
f(Test())
but mypy complains about this
error: Argument 1 of "__contains__" incompatible with supertype "Container"
But then I have found this code snippet in #18
defassertIn(item: T, thing: Intersection[Iterable[T], Container[T]]) ->None:
ifitemnotinthing:
# Debug outputforitinthing:
print(it)
Which is exactly what I want, and it is also much cleaner than introducing an auxiliary "mix" class. Maybe then introducing Intersection is a good idea, @JukkaL is it easy to implement it in mypy?
This question has already been discussed in #18 long time ago, but now I stumble on this in a practical question: How to annotate something that subclasses two ABC's. Currently, a workaround is to introduce a "mix" class:
but mypy complains about this
But then I have found this code snippet in #18
Which is exactly what I want, and it is also much cleaner than introducing an auxiliary "mix" class. Maybe then introducing
Intersectionis a good idea, @JukkaL is it easy to implement it in mypy?