Comment

Comment by thr0w4w4y1337

from typing import Protocol, TypeVar

T_co = TypeVar("T_co", covariant=True)

class Indexable(Protocol[T_co]): def __getitem__(self, i: int) -> T_co: ...

def f(x: Indexable[str]) -> None: print(x[0])

I am failing to format it proprely here, but you get the idea.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton