mypy error on incompatible type SupportsIndex for list.__imul__

Viewed 200

I am subclassing list with a definition for __imul__().

from __future__ import annotations

from typing import SupportsIndex


class CustomList(list):
    def __imul__(self, n: SupportsIndex) -> CustomList:
        return super().__imul__(n)

mypy 0.910 with Python 3.9.2 raises an error that the argument type is incompatible.

customlist.py:8: error: Argument 1 to "__imul__" of "list" has incompatible type "SupportsIndex"; expected "int"

This doesn't make sense to me. __imul__() definitely accepts a SupportsIndex argument. Per the docs:

  1. The value n is an integer, or an object implementing __index__().

Is this a bug in mypy? Is there a way to resolve this error without adding a local ignore?

0 Answers
Related