Typing and Generics
typing.SupportsIndex
Runtime-checkable protocol for objects providing __index__(). A static checker checks the method contract; runtime membership checks only inspect the presence of the required member, not its signature or return type.
Formal Syntax & Structure
python syntaxpython
typing.SupportsIndexReturn Value
protocol class
Typing construct or runtime result as described; static typing rules are not runtime validation.
Working Example
Example Snippetpython
from typing import SupportsIndex
class Value: def __index__(self): return 2item=Value()print((isinstance(item,SupportsIndex), [10,20,30][item]))