On this page
  1. typing.SupportsIndex
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

typing.SupportsIndex

Prev: typing.SupportsFloat | Up: typing | Next: typing.SupportsInt
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.SupportsIndex
Tags: #public #python3 #stdlib #typing


Import

import typing
from typing import SupportsIndex

Signature & Overview

typing.SupportsIndex(*args, **kwargs)

A protocol with one abstract method index.

Usage

from typing import SupportsIndex

class Idx:
    def __index__(self) -> int: return 1

items = ["a", "b", "c"]
assert isinstance(Idx(), SupportsIndex) and items[Idx()] == "b"

Gotchas

REPL Inspect

from typing import SupportsIndex
help(SupportsIndex)

Linked from

Related notes